From 6d993d300714906b2cd6912b1aa3245b1c71ef3c Mon Sep 17 00:00:00 2001 From: gunarathnemdd Date: Mon, 11 Jul 2016 21:21:11 +0530 Subject: [PATCH 1/5] Changed ArtifactID to E12103_lab2 in pom.xml --- pom.xml | 2 +- .../studentSystem/StudentRegisterTest.java | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index ec9ccc4..a4571f8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 CO314 - lab2 + E12103_lab2 1.0-SNAPSHOT diff --git a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java index a331c44..25ee9a3 100644 --- a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java +++ b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java @@ -6,10 +6,7 @@ public class StudentRegisterTest { StudentRegister register; @Before - public void setupTest() - { - System.out.println("A new test is starting."); - } + public void setupTest() { System.out.println("A new test is starting.");} @After public void finishTest() @@ -52,7 +49,20 @@ public void testAddStudent() public void testAddStudentTwice() { // Implement your test code here. Adding a student with same registration number twice should generate an exception. - Assert.fail("Test case is not yet implemented for adding student twice. So it is set to fail always"); + //Assert.fail("Test case is not yet implemented for adding student twice. So it is set to fail always"); + register = new StudentRegister(); + String expected = "StudentID already exists in the register"; + String actual = "Not initialized a message yet"; + try{ + register.addStudent(new Student(5, "fawzan", "mohomad")); + register.addStudent(new Student(5, "dhanuka", "dilsan")); + } + catch (Exception e){ + actual = e.getMessage(); + } + System.out.println("Testing add student twice method"); + + Assert.assertEquals(expected,actual); } @Test From 29bdd7073c92f5451d79650d02c65c1a03ae596c Mon Sep 17 00:00:00 2001 From: gunarathnemdd Date: Mon, 11 Jul 2016 21:23:59 +0530 Subject: [PATCH 2/5] Implimented the testAddStudentTwice.java --- .../java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java index 25ee9a3..0340826 100644 --- a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java +++ b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java @@ -52,7 +52,7 @@ public void testAddStudentTwice() //Assert.fail("Test case is not yet implemented for adding student twice. So it is set to fail always"); register = new StudentRegister(); String expected = "StudentID already exists in the register"; - String actual = "Not initialized a message yet"; + String actual = "Not initialized a message yet!"; try{ register.addStudent(new Student(5, "fawzan", "mohomad")); register.addStudent(new Student(5, "dhanuka", "dilsan")); From 1cf765a4d3ff6f028a236412471790903019e548 Mon Sep 17 00:00:00 2001 From: gunarathnemdd Date: Mon, 11 Jul 2016 21:26:42 +0530 Subject: [PATCH 3/5] Changet @Before method to create new student register --- .../ac/pdn/co328/studentSystem/StudentRegisterTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java index 0340826..4468eac 100644 --- a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java +++ b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java @@ -6,7 +6,10 @@ public class StudentRegisterTest { StudentRegister register; @Before - public void setupTest() { System.out.println("A new test is starting.");} + public void setupTest() { + register = new StudentRegister(); + System.out.println("A new test is starting."); + } @After public void finishTest() @@ -29,7 +32,6 @@ public static void afterClass() @Test public void testAddStudent() { - register = new StudentRegister(); try { register.addStudent(new Student(2, "nimal", "kumara")); @@ -50,7 +52,6 @@ public void testAddStudentTwice() { // Implement your test code here. Adding a student with same registration number twice should generate an exception. //Assert.fail("Test case is not yet implemented for adding student twice. So it is set to fail always"); - register = new StudentRegister(); String expected = "StudentID already exists in the register"; String actual = "Not initialized a message yet!"; try{ @@ -68,7 +69,6 @@ public void testAddStudentTwice() @Test public void testRemoveStudent() { - register = new StudentRegister(); try { register.addStudent(new Student(2, "nimal", "kumara")); @@ -87,7 +87,6 @@ public void testRemoveStudent() @Test public void testGetRegNumbers() { - register = new StudentRegister(); try { register.addStudent(new Student(1, "ruwan", "tharaka")); From 35776da4bcd0a5017b87c530f0006b062fc0f009 Mon Sep 17 00:00:00 2001 From: gunarathnemdd Date: Mon, 11 Jul 2016 22:13:57 +0530 Subject: [PATCH 4/5] Implimented testFindByName method --- .../co328/studentSystem/StudentRegisterTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java index 4468eac..7118a89 100644 --- a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java +++ b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java @@ -58,8 +58,8 @@ public void testAddStudentTwice() register.addStudent(new Student(5, "fawzan", "mohomad")); register.addStudent(new Student(5, "dhanuka", "dilsan")); } - catch (Exception e){ - actual = e.getMessage(); + catch (Exception ex){ + actual = ex.getMessage(); } System.out.println("Testing add student twice method"); @@ -79,6 +79,7 @@ public void testRemoveStudent() { Assert.fail("Add student failed"); } + System.out.println("Testing remove student method"); register.removeStudent(1); Student student = register.findStudent(1); Assert.assertNull("student was not removed",student); @@ -97,6 +98,7 @@ public void testGetRegNumbers() { Assert.fail("Adding student failed"); } + System.out.println("Testing get register number method"); ArrayList numbers = register.getAllRegistrationNumbers(); ArrayList expected = new ArrayList(); expected.add(1); @@ -104,4 +106,14 @@ public void testGetRegNumbers() expected.add(5); Assert.assertTrue(numbers.equals(expected)); } + + @Test + public void testFindByName() + { + System.out.println("Testing find by name method"); + ArrayList students = register.findStudentsByName("nimal"); + Assert.assertNotNull("Student is in",students); + } + + } From 196a3407d4d9454fd6e4d48930327aeabdf99cb2 Mon Sep 17 00:00:00 2001 From: gunarathnemdd Date: Mon, 11 Jul 2016 22:33:18 +0530 Subject: [PATCH 5/5] Implimented testCleanRegister method --- .../co328/studentSystem/StudentRegisterTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java index 7118a89..1edea1b 100644 --- a/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java +++ b/src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java @@ -115,5 +115,18 @@ public void testFindByName() Assert.assertNotNull("Student is in",students); } + @Test + public void testCleanRegister() + { + register.reset(); + System.out.println("Testing clean register method"); + ArrayList index_num; + try { + index_num = register.getAllRegistrationNumbers(); + Assert.assertNotNull("register is not cleared",index_num); + }catch (NullPointerException ex){ + System.out.println("Register is cleared"); + } + } }