ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 29 Apr 2017 My Price 11.00

methods to pass the Java tests

Can anyone please pass the methods to pass the Java tests that I have attached with proper Javadoc comments. 

 

 

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment1; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*; /**
*
* @author krupa
*/
public class InstructorTest { public InstructorTest() {
} @BeforeClass
public static void setUpClass() {
} @AfterClass
public static void tearDownClass() { } @Before
public void setUp() {
} @After
public void tearDown() {
} @Test
public void testSomeMethod() { }
public class InstructorTest {
Instructor validInstructor; public InstructorTest() {
} @BeforeClass
public static void setUpClass() {
} @AfterClass
public static void tearDownClass() {
} @Before public void setUp() {
validInstructor = new Instructor("Alga", "Rithem","14 Knowledge Ave", "Utopia", "ON", "Y6Y3D3",
LocalDate.of(1974, Month.DECEMBER, 31), 2000123, LocalDate.of(2015,
Month.JANUARY, 1));
} @After
public void tearDown() {
} /**
* Test of setHireDate method, of class Instructor.
*/
@Test
public void testSetHireDateValid() {
LocalDate dateHired = LocalDate.of(2014, Month.JANUARY, 1);
validInstructor.setHireDate(dateHired);
assertEquals(validInstructor.getHireDate(), LocalDate.of(2014, Month.JANUARY, 1));
} /**
* Test of setHireDate method, of class Instructor.
*/
@Test
public void testSetHireDateInvalid() {
LocalDate dateHired = LocalDate.of(2018, Month.JANUARY, 1);
try
{
validInstructor.setHireDate(dateHired); fail("The hire date is in the future and should have triggered an exception");
}
catch (IllegalArgumentException e)
{
System.out.printf("Hire date in the future, exception = \"%s\"%n", e.getMessage());
}
} /**
* Test of setHireDate method, of class Instructor.
*/
@Test
public void testSetHireDateInvalid2() {
LocalDate dateHired = LocalDate.of(1900, Month.JANUARY, 1);
try
{
validInstructor.setHireDate(dateHired);
fail("The hire date was more than 80 years ago, it should throw an exception.");
}
catch (IllegalArgumentException e)
{
System.out.printf("Hire date in the future, exception = \"%s\"%n", e.getMessage());
}
} /**
* Test of addTeachableCourse method, of class Instructor. */
@Test
public void testAddTeachableCourse() {
String courseCode = "COMP1008";
validInstructor.addTeachableCourse(courseCode);
ArrayList<String> expResult = new ArrayList<>();
expResult.add("COMP1008");
assertEquals(validInstructor.getTeachableCourses(), expResult);
} /**
* Test of getYearsAtCollege method, of class Instructor.
*/
@Test
public void testGetYearsAtCollegeAfterAnniversary() {
int expResult = 2;
int result = validInstructor.getYearsAtCollege();
assertEquals(expResult, result);
} /**
* Test of getYearsAtCollege method, of class Instructor.
*/
@Test
public void testGetYearsAtCollegeBeforeAnniversary() {
int expResult = 16;
validInstructor.setHireDate(LocalDate.of(2000, Month.DECEMBER, 31));
int result = validInstructor.getYearsAtCollege();
assertEquals(expResult, result); } /**
* Test of canTeach method, of class Instructor.
*/
@Test
public void testCanTeachFalse() {
String courseCode = "COMP1008";
boolean expResult = false;
boolean result = validInstructor.canTeach(courseCode);
assertEquals(expResult, result);
} /**
* Test of canTeach method, of class Instructor.
*/
@Test
public void testCanTeachTrue() {
String courseCode = "comp1008";
boolean expResult = true;
validInstructor.addTeachableCourse(courseCode);
boolean result = validInstructor.canTeach(courseCode);
assertEquals(expResult, result);
} /** * Test of listOfSubjectsCertifiedToTeach method, of class Instructor.
*/
@Test
public void testListOfSubjectsCertifiedToTeach() {
String expResult = "COMP1008, COMP2003";
validInstructor.addTeachableCourse("COMP1008");
validInstructor.addTeachableCourse("COMP2003");
String result = validInstructor.listOfSubjectsCertifiedToTeach();
assertEquals(expResult, result);
} /**
* Test of the constructor with an invalid employee number
*/
@Test
public void testInstructorSetupInvalidEmployeeNumber() { try
{
Instructor invalidInstructor = new Instructor("Alga", "Rithem","14 Knowledge Ave", "Utopia",
"ON", "Y6Y3DR",
LocalDate.of(1974, Month.DECEMBER, 31), 0, LocalDate.of(2015, Month.JANUARY, 1));
fail("The employee number is not valid");
}
catch (IllegalArgumentException e)
{
System.out.printf("Instructor constructor with invalid employee number exception = \"%s\"%n",
e.getMessage());
}
} /**
* Test of canTeach method, of class Instructor.
*/
@Test
public void testCanTeach() {
String courseCode = "COMP1007";
boolean expResult = false;
boolean result = validInstructor.canTeach(courseCode);
assertEquals(expResult, result);
} /**
* Test of canTeach method, of class Instructor.
*/
@Test
public void testCanTeach2() {
String courseCode = "COMP1008";
validInstructor.addTeachableCourse(courseCode);
boolean expResult = true;
boolean result = validInstructor.canTeach(courseCode);
assertEquals(expResult, result);
} /**
* Test of getHireDate method, of class Instructor.
*/
@Test public void testGetHireDate() {
LocalDate expResult = LocalDate.of(2015, Month.JANUARY, 1);
LocalDate result = validInstructor.getHireDate();
assertEquals(expResult, result);
} /**
* Test of getEmployeeNum method, of class Instructor.
*/
@Test
public void testGetEmployeeNum() {
int expResult = 2000123;
int result = validInstructor.getEmployeeNum();
assertEquals(expResult, result);
} /**
* Test of getTeachableCourses method, of class Instructor.
*/
@Test
public void testGetTeachableCourses() {
validInstructor.addTeachableCourse("comp1008");
ArrayList<String> expResult = new ArrayList<>();
expResult.add("COMP1008");
ArrayList<String> result = validInstructor.getTeachableCourses();
assertEquals(expResult, result);
} /** * Test of getYearsAtCollege method, of class Instructor.
*/
@Test
public void testGetYearsAtCollege() {
int expResult = 2;
int result = validInstructor.getYearsAtCollege();
assertEquals(expResult, result);
} /**
* Test of setBirthday method, of class Instructor.
*/
@Test
public void testSetBirthdayOver100() {
LocalDate birthday = LocalDate.of(1900, Month.MARCH, 1);
try
{
validInstructor.setBirthday(birthday);
}
catch (IllegalArgumentException e)
{
System.out.printf("Test set birthday over 100 exception = \"%s\"%n", e.getMessage());
}
} /**
* Test of setBirthday method, of class Instructor.
*/
@Test public void testSetBirthdayUnder18() {
LocalDate birthday = LocalDate.of(2014, Month.MARCH, 1);
try
{
validInstructor.setBirthday(birthday);
fail("The setBirthday method should have found the Instructor to be too young");
}
catch (IllegalArgumentException e)
{
System.out.printf("Test set birthday under 18, exception = \"%s\"%n", e.getMessage());
} } }
}

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment1; import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*; /**
*
* @author krupa
*/
public class StudentTest { public StudentTest() {
} @BeforeClass
public static void setUpClass() {
} @AfterClass
public static void tearDownClass() { } @Before
public void setUp() {
} @After
public void tearDown() {
} @Test
public void testSomeMethod() { }
public class StudentTest { Student validStudent1; public StudentTest() {
} @BeforeClass
public static void setUpClass() { } @AfterClass
public static void tearDownClass() {
} @Before
public void setUp() {
validStudent1 = new Student("Fred","Flintstone","13 Cobble Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2000, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.JANUARY, 10));
} @After
public void tearDown() {
} /**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayValidInput() {
LocalDate expResult = LocalDate.of(2000, Month.DECEMBER, 10);
validStudent1.setBirthdate(expResult);
LocalDate result = validStudent1.getBirthdate();
assertEquals(expResult, result);
} /**
* Test of setBirthday method, of class Student.
*/
@Test
public void testSetBirthdayInvalidInput() { LocalDate invalidBirthdate = LocalDate.of(1000, Month.DECEMBER, 10);
try{
validStudent1.setBirthdate(invalidBirthdate);
fail("The invalid date did not throw an exception");
}
catch (IllegalArgumentException e)
{
LocalDate expResult = LocalDate.of(2000, Month.SEPTEMBER, 03);
LocalDate result = validStudent1.getBirthdate();
assertEquals(expResult, result);
}
} /**
* Test of getYearEnrolled method, of class Student.
*/
@Test
public void testGetYearEnrolled() {
int expResult = 2016;
int result = validStudent1.getYearEnrolled();
assertEquals(expResult, result);
} /**
* Test of inGoodStanding method, of class Student.
*/
@Test public void testInGoodStanding() {
boolean expResult = true;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result);
} /**
* Test of suspendStudent method, of class Student.
*/
@Test
public void testSuspendStudent() {
validStudent1.suspendStudent();
boolean expResult = false;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result);
} /**
* Test of reinstateStudent method, of class Student.
*/
@Test
public void testReinstateStudent() {
validStudent1.suspendStudent();
validStudent1.reinstateStudent();
boolean expResult = true;
boolean result = validStudent1.inGoodStanding();
assertEquals(expResult, result); } /**
* Test of changeAddress method, of class Student.
*/
@Test
public void testChangeAddress() {
String street = "55 Granite Ridge Road";
String city = "Bedrock";
String province = "Dendi";
String postalCode = "B3B2T2";
validStudent1.changeAddress(street, city, province, postalCode);
String expResult = "55 Granite Ridge Road, Bedrock, Dendi, B3B2T2";
String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
} /**
* Test of changeAddress method, of class Student.
*/
@Test
public void testChangeAddressInvalidPostalCode() {
String street = "55 Granite Ridge Road";
String city = "Bedrock";
String province = "Dendi";
String postalCode = "b3b2t2";
validStudent1.changeAddress(street, city, province, postalCode);
String expResult = "55 Granite Ridge Road, Bedrock, Dendi, B3B2T2"; String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
} /**
* Test of getAddress method, of class Student.
*/
@Test
public void testGetAddress() {
String expResult = "13 Cobble Way, Bedrock, Dendi, A2A0T3";
String result = validStudent1.getFullAddress();
assertEquals(expResult, result);
} /**
* Test of toString method, of class Student.
*/
@Test
public void testToString() {
String expResult = "Fred Flintstone, student number is 1234";
String result = validStudent1.toString();
assertEquals(expResult, result);
} /**
* Test of getYearsAtCollege method, of class Student.
*/
@Test
public void testGetYearsAtCollege() { int expResult = 1;
int result = validStudent1.getYearsAtCollege();
assertEquals(expResult, result);
} /**
* Test of setBirthdate method, of class Student.
*/
@Test
public void testSetBirthdateValid() {
LocalDate newBirthdate = LocalDate.of(2000, Month.APRIL, 1);
validStudent1.setBirthdate(newBirthdate);
assertEquals(newBirthdate, validStudent1.getBirthdate());
} /**
* Test of setBirthdate method, of class Student.
*/
@Test
public void testSetBirthdateInvalid() {
LocalDate newBirthdate = LocalDate.of(2016, Month.APRIL, 1);
try
{
validStudent1.setBirthdate(newBirthdate);
fail("The setBirthday method should have ensured that the student is at least 14");
}
catch (IllegalArgumentException e)
{ System.out.printf("The setBirthday with too young of an input, exception = \"%s\"%n",
e.getMessage());
} } /**
* Test of setBirthdate method, of class Student.
*/
@Test
public void testSetBirthdateInvalid2() {
LocalDate newBirthdate = LocalDate.of(1897, Month.APRIL, 1);
try
{
validStudent1.setBirthdate(newBirthdate);
fail("The setBirthday method should have ensured that the student is older than 90");
}
catch (IllegalArgumentException e)
{
System.out.printf("The setBirthday with a birthday too old, exception = \"%s\"%n",
e.getMessage());
}
} /**
* Test of creating a Student that is not a valid age (too old)
*/
@Test public void testSetBirthdateInvalid3() { try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble
Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(1900, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because this one is older than 90");
}
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student was too old, exception = \"%s\"%n",
e.getMessage());
}
} /**
* Test of creating a Student that is not a valid age (too young)
*/
@Test
public void testSetBirthdateInvalid4() { try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble
Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2014, Month.SEPTEMBER, 3),"COPA", 1234,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because this one is too young"); }
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student was too young, exception
= \"%s\"%n", e.getMessage());
}
} /**
* Test of creating a Student with an invalid student number
*/
@Test
public void testSetBirthdateInvalid5() { try
{
Student invalidStudent = new Student("Fred","Flintstone","13 Cobble
Way","Bedrock","Dendi","A2A0T3",
LocalDate.of(2000, Month.SEPTEMBER, 3),"COPA", 0,
LocalDate.of(2016, Month.MARCH, 10));
fail("The student constructor should have failed because of an invalid student number");
}
catch (IllegalArgumentException e)
{
System.out.printf("The constructor caught that the student had an invalid student number,
exception = \"%s\"%n", e.getMessage());
}
} } }

 

Attachments:

Answers

(11)
Status NEW Posted 29 Apr 2017 07:04 AM My Price 11.00

-----------

Not Rated(0)