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

E/12/083 #39

Open
wants to merge 2 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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>E12083_lab2</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public ArrayList<Student> findStudentsByName(String name)
{
if(studentList.get(i).getFirstName().contains(name))
{
studentList.add(studentList.get(i));
students.add(studentList.get(i));
}


if(studentList.get(i).getLastName().contains(name))
{
studentList.add(studentList.get(i));
students.add(studentList.get(i));
}
}
return students;
Expand Down
111 changes: 84 additions & 27 deletions src/test/java/lk/ac/pdn/co328/studentSystem/StudentRegisterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
public class StudentRegisterTest {
StudentRegister register;

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

@After
public void finishTest()
{
System.out.println("Test finished");
}

@BeforeClass
public static void beforeClass()
{
Expand All @@ -29,13 +17,35 @@ public static void afterClass()
System.out.println("All tests are done");
}

@Before
public void setupTest()
{

register = new StudentRegister();
try
{
register.addStudent(new Student(2, "nimal", "kumara"));

}
catch (Exception ex)
{
Assert.fail("Adding student failed");
}
}

@After
public void finishTest()
{
System.out.println("Test finished");
}

@Test
public void testAddStudent()
{
register = new StudentRegister();

try
{
register.addStudent(new Student(2, "nimal", "kumara"));

register.addStudent(new Student(5, "fawzan", "mohomad"));
}
catch (Exception ex)
Expand All @@ -51,17 +61,26 @@ public void testAddStudent()
@Test
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");

try
{
register.addStudent(new Student(2, "nimal", "kumara"));
//register.addStudent(new Student(2, "nimal", "kumara"));

}
catch (Exception ex)
{
System.out.println("Adding student failed"); // this exeption means test pass
}

}

@Test
public void testRemoveStudent()
{
register = new StudentRegister();

try
{
register.addStudent(new Student(2, "nimal", "kumara"));
register.addStudent(new Student(1, "ruwan", "tharaka"));
register.addStudent(new Student(5, "gayan", "chamara"));
}
Expand All @@ -77,22 +96,60 @@ public void testRemoveStudent()
@Test
public void testGetRegNumbers()
{

try
{
register.addStudent(new Student(1, "ruwan", "tharaka"));
register.addStudent(new Student(5, "gayan", "chamara"));
}
catch (Exception ex)
{
Assert.fail("Add student failed");
}
ArrayList<Integer> numbers = register.getAllRegistrationNumbers();
ArrayList<Integer> expected = new ArrayList<Integer>();
expected.add(2);
expected.add(1);
expected.add(5);

Assert.assertTrue(numbers.equals(expected));
}

@Test
public void testfindStudentsByName(){

register = new StudentRegister();
try
{
register.addStudent(new Student(1, "ruwan", "tharaka"));
register.addStudent(new Student(2, "nimal", "kumara"));
register.addStudent(new Student(5, "gayan", "chamara"));
register.addStudent(new Student(5, "gayan", "ruwan"));
}
catch (Exception ex)
{
Assert.fail("Adding student failed");
Assert.fail("Add student failed");
}

ArrayList<Student> got = register.findStudentsByName("ruwan");
ArrayList<Student> expected = new ArrayList<Student>();
expected.add(new Student(1, "ruwan", "tharaka"));
Assert.assertTrue(got.get(0).getFirstName().equals("ruwan"));
Assert.assertTrue(got.get(1).getLastName().equals("ruwan"));
}
@Test
public void testCleanStudentRegestor() {
register = new StudentRegister();
try {
register.addStudent(new Student(1, "ruwan", "tharaka"));
register.addStudent(new Student(5, "gayan", "chamara"));
} catch (Exception ex) {
Assert.fail("Add student failed");
}
register.reset();
try {

ArrayList<Integer> numbers = register.getAllRegistrationNumbers();
} catch (NullPointerException e) {
System.out.print("NullPointerException caught"); // this exeption means regestor is cleaned
}
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));
}
}