Minor refactorings and code style changes (#807)
* Made minor changes in some patterns such as removed throws clause where not needed, changed incorrect order of arguments in assertEquals * Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments * Removed unused import from Promise * Addressed review comments * Addressed checkstyle issue
This commit is contained in:
@ -21,6 +21,7 @@ package com.iluwatar.datamapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
|
||||
@ -43,27 +44,29 @@ public class DataMapperTest {
|
||||
final StudentDataMapper mapper = new StudentDataMapperImpl();
|
||||
|
||||
/* Create new student */
|
||||
Student student = new Student(1, "Adam", 'A');
|
||||
int studentId = 1;
|
||||
Student student = new Student(studentId, "Adam", 'A');
|
||||
|
||||
/* Add student in respectibe db */
|
||||
mapper.insert(student);
|
||||
|
||||
/* Check if student is added in db */
|
||||
assertEquals(student.getStudentId(), mapper.find(student.getStudentId()).get().getStudentId());
|
||||
assertEquals(studentId, mapper.find(student.getStudentId()).get().getStudentId());
|
||||
|
||||
/* Update existing student object */
|
||||
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
|
||||
String updatedName = "AdamUpdated";
|
||||
student = new Student(student.getStudentId(), updatedName, 'A');
|
||||
|
||||
/* Update student in respectibe db */
|
||||
mapper.update(student);
|
||||
|
||||
/* Check if student is updated in db */
|
||||
assertEquals(mapper.find(student.getStudentId()).get().getName(), "AdamUpdated");
|
||||
assertEquals(updatedName, mapper.find(student.getStudentId()).get().getName());
|
||||
|
||||
/* Delete student in db */
|
||||
mapper.delete(student);
|
||||
|
||||
/* Result should be false */
|
||||
assertEquals(false, mapper.find(student.getStudentId()).isPresent());
|
||||
assertFalse(mapper.find(student.getStudentId()).isPresent());
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ package com.iluwatar.datamapper;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@ -28,28 +30,27 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*/
|
||||
public final class StudentTest {
|
||||
|
||||
@Test
|
||||
/**
|
||||
* This API tests the equality behaviour of Student object
|
||||
* Object Equality should work as per logic defined in equals method
|
||||
*
|
||||
* @throws Exception if any execution error during test
|
||||
*/
|
||||
@Test
|
||||
public void testEquality() throws Exception {
|
||||
|
||||
/* Create some students */
|
||||
final Student firstStudent = new Student(1, "Adam", 'A');
|
||||
final Student secondStudent = new Student(2, "Donald", 'B');
|
||||
final Student secondSameStudent = new Student(2, "Donald", 'B');
|
||||
final Student firstSameStudent = firstStudent;
|
||||
|
||||
/* Check equals functionality: should return 'true' */
|
||||
assertTrue(firstStudent.equals(firstSameStudent));
|
||||
assertEquals(firstStudent, firstStudent);
|
||||
|
||||
/* Check equals functionality: should return 'false' */
|
||||
assertFalse(firstStudent.equals(secondStudent));
|
||||
assertNotEquals(firstStudent, secondStudent);
|
||||
|
||||
/* Check equals functionality: should return 'true' */
|
||||
assertTrue(secondStudent.equals(secondSameStudent));
|
||||
assertEquals(secondStudent, secondSameStudent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user