First review changes++

First review changes++
This commit is contained in:
Amit Dixit
2016-04-18 13:14:20 +05:30
parent 06e0a15400
commit 8529d6e34b
9 changed files with 118 additions and 249 deletions

View File

@@ -1,6 +1,5 @@
/**
* The MIT License Copyright (c) 2016 Amit Dixit
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,

View File

@@ -24,8 +24,7 @@ import org.junit.Test;
import com.iluwatar.datamapper.Student;
import com.iluwatar.datamapper.StudentDataMapper;
import com.iluwatar.datamapper.StudentFirstDataMapper;
import com.iluwatar.datamapper.StudentSecondDataMapper;
import com.iluwatar.datamapper.StudentDataMapperImpl;
/**
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
@@ -45,41 +44,7 @@ public class DataMapperTest {
public void testFirstDataMapper() {
/* Create new data mapper of first type */
final StudentDataMapper mapper = new StudentFirstDataMapper();
/* Create new student */
Student student = new Student(1, "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());
/* Update existing student object */
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
/* Update student in respectibe db */
mapper.update(student);
/* Check if student is updated in db */
assertEquals(mapper.find(student.getStudentId()).get().getName(), "AdamUpdated");
/* Delete student in db */
mapper.delete(student);
/* Result should be false */
assertEquals(false, mapper.find(student.getStudentId()).isPresent());
}
/**
* This test verify that second data mapper is able to perform all CRUD operations on Student
*/
@Test
public void testSecondDataMapper() {
/* Create new data mapper of second type */
final StudentDataMapper mapper = new StudentSecondDataMapper();
final StudentDataMapper mapper = new StudentDataMapperImpl();
/* Create new student */
Student student = new Student(1, "Adam", 'A');

View File

@@ -0,0 +1,50 @@
/**
* The MIT License Copyright (c) 2016 Amit Dixit
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.iluwatar.datamapper;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
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
*/
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));
/* Check equals functionality: should return 'false' */
assertFalse(firstStudent.equals(secondStudent));
/* Check equals functionality: should return 'true' */
assertTrue(secondStudent.equals(secondSameStudent));
}
}