Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E12103_Lab02 #29

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CO314</groupId>
<artifactId>lab2</artifactId>
<artifactId>E12103_lab2</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class StudentRegisterTest {
StudentRegister register;

@Before
public void setupTest()
{
public void setupTest() {
register = new StudentRegister();
System.out.println("A new test is starting.");
}

Expand All @@ -32,7 +32,6 @@ public static void afterClass()
@Test
public void testAddStudent()
{
register = new StudentRegister();
try
{
register.addStudent(new Student(2, "nimal", "kumara"));
Expand All @@ -52,13 +51,24 @@ 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");
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 ex){
actual = ex.getMessage();
}
System.out.println("Testing add student twice method");

Assert.assertEquals(expected,actual);
}

@Test
public void testRemoveStudent()
{
register = new StudentRegister();
try
{
register.addStudent(new Student(2, "nimal", "kumara"));
Expand All @@ -69,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);
Expand All @@ -77,7 +88,6 @@ public void testRemoveStudent()
@Test
public void testGetRegNumbers()
{
register = new StudentRegister();
try
{
register.addStudent(new Student(1, "ruwan", "tharaka"));
Expand All @@ -88,11 +98,35 @@ public void testGetRegNumbers()
{
Assert.fail("Adding student failed");
}
System.out.println("Testing get register number method");
ArrayList<Integer> numbers = register.getAllRegistrationNumbers();
ArrayList<Integer> expected = new ArrayList<Integer>();
expected.add(1);
expected.add(2);
expected.add(5);
Assert.assertTrue(numbers.equals(expected));
}

@Test
public void testFindByName()
{
System.out.println("Testing find by name method");
ArrayList<Student> students = register.findStudentsByName("nimal");
Assert.assertNotNull("Student is in",students);
}

@Test
public void testCleanRegister()
{
register.reset();

System.out.println("Testing clean register method");
ArrayList<Integer> index_num;
try {
index_num = register.getAllRegistrationNumbers();
Assert.assertNotNull("register is not cleared",index_num);
}catch (NullPointerException ex){
System.out.println("Register is cleared");
}
}
}