@@ -46,8 +46,7 @@ public class DbCustomerDaoTest {
4646 public void createSchema () throws SQLException {
4747 try (Connection connection = DriverManager .getConnection (DB_URL );
4848 Statement statement = connection .createStatement ()) {
49- statement .execute ("CREATE TABLE CUSTOMERS (ID NUMBER, FNAME VARCHAR(100),"
50- + " LNAME VARCHAR(100))" );
49+ statement .execute (CustomerSchemaSql .CREATE_SCHEMA_SQL );
5150 }
5251 }
5352
@@ -85,7 +84,7 @@ public void addingShouldResultInSuccess() throws Exception {
8584 assertTrue (result );
8685
8786 assertCustomerCountIs (2 );
88- assertEquals (nonExistingCustomer , dao .getById (nonExistingCustomer .getId ()));
87+ assertEquals (nonExistingCustomer , dao .getById (nonExistingCustomer .getId ()). get () );
8988 }
9089
9190 @ Test
@@ -106,12 +105,12 @@ public void updationShouldBeFailureAndNotAffectExistingCustomers() throws Except
106105 boolean result = dao .update (customer );
107106
108107 assertFalse (result );
109- assertNull (dao .getById (nonExistingId ));
108+ assertFalse (dao .getById (nonExistingId ). isPresent ( ));
110109 }
111110
112111 @ Test
113- public void retrieveShouldReturnNull () throws Exception {
114- assertNull (dao .getById (getNonExistingCustomerId ()));
112+ public void retrieveShouldReturnNoCustomer () throws Exception {
113+ assertFalse (dao .getById (getNonExistingCustomerId ()). isPresent ( ));
115114 }
116115 }
117116
@@ -130,7 +129,7 @@ public void addingShouldResultInFailureAndNotAffectExistingCustomers() throws Ex
130129
131130 assertFalse (result );
132131 assertCustomerCountIs (1 );
133- assertEquals (existingCustomer , dao .getById (existingCustomer .getId ()));
132+ assertEquals (existingCustomer , dao .getById (existingCustomer .getId ()). get () );
134133 }
135134
136135 @ Test
@@ -139,7 +138,7 @@ public void deletionShouldBeSuccessAndCustomerShouldBeNonAccessible() throws Exc
139138
140139 assertTrue (result );
141140 assertCustomerCountIs (0 );
142- assertNull (dao .getById (existingCustomer .getId ()));
141+ assertFalse (dao .getById (existingCustomer .getId ()). isPresent ( ));
143142 }
144143
145144 @ Test
@@ -151,7 +150,7 @@ public void updationShouldBeSuccessAndAccessingTheSameCustomerShouldReturnUpdate
151150
152151 assertTrue (result );
153152
154- final Customer cust = dao .getById (existingCustomer .getId ());
153+ final Customer cust = dao .getById (existingCustomer .getId ()). get () ;
155154 assertEquals (newFirstname , cust .getFirstName ());
156155 assertEquals (newLastname , cust .getLastName ());
157156 }
@@ -207,12 +206,12 @@ public void updatingACustomerFailsWithFeedbackToTheClient() throws Exception {
207206 }
208207
209208 @ Test
210- public void retrievingACustomerByIdReturnsNull () throws Exception {
209+ public void retrievingACustomerByIdFailsWithExceptionAsFeedbackToClient () throws Exception {
211210 dao .getById (existingCustomer .getId ());
212211 }
213212
214213 @ Test
215- public void retrievingAllCustomersReturnsAnEmptyStream () throws Exception {
214+ public void retrievingAllCustomersFailsWithExceptionAsFeedbackToClient () throws Exception {
216215 dao .getAll ();
217216 }
218217
@@ -226,7 +225,7 @@ public void retrievingAllCustomersReturnsAnEmptyStream() throws Exception {
226225 public void deleteSchema () throws SQLException {
227226 try (Connection connection = DriverManager .getConnection (DB_URL );
228227 Statement statement = connection .createStatement ()) {
229- statement .execute ("DROP TABLE CUSTOMERS" );
228+ statement .execute (CustomerSchemaSql . DELETE_SCHEMA_SQL );
230229 }
231230 }
232231
0 commit comments