/** Test comparator */ public void testComparator() { Exception exception = null; student = new Student(); student.setList(songList); student.setMajor(major); student.setHobby(hobby); student.setRegion(region); student.setHeard(num1); student.setLikes(num3); Student student2 = new Student(); student2.setList(songList); student2.setMajor("asdf"); student2.setHobby("asdf"); student2.setRegion("asd"); student2.setHeard(num3); student2.setLikes(num1); Type type = Type.ARTIST; try { student.compare(student2, type); } catch (Exception e) { exception = e; } assertNotNull(exception); assertTrue(exception instanceof UnsupportedOperationException); }
/** test equals */ public void testEquals() { Student student3 = null; assertFalse(student.equals(student3)); assertTrue(student.equals(student)); assertFalse(student.equals(new Object())); Student sameStudent = new Student(); sameStudent.setHobby(hobby); sameStudent.setMajor(major); sameStudent.setRegion(region); assertTrue(student.equals(sameStudent)); Student diffStudent = new Student(); diffStudent.setHobby("x"); diffStudent.setMajor(major); diffStudent.setRegion(region); assertFalse(student.equals(diffStudent)); diffStudent.setMajor("x"); assertFalse(student.equals(diffStudent)); diffStudent.setRegion("x"); assertFalse(student.equals(diffStudent)); diffStudent.setHobby(hobby); assertFalse(student.equals(diffStudent)); diffStudent.setRegion(region); assertFalse(student.equals(diffStudent)); diffStudent.setHobby(hobby); assertFalse(student.equals(diffStudent)); }
public static void main(String[] args) { Colleges c = new Colleges(); Student s = new Student(); Teacher t = new Teacher(); c.setName("***科技学院"); c.setNum(16000); c.setArea(800); s.setName1("秦*盛"); s.setGrade("测绘B111"); s.setMajor("建筑工程学院"); t.setName("王老师"); t.setCurriculum("Java 编程"); System.out.println(c.getName() + " 有 " + c.getNum() + "名学生" + "占地面积" + c.getArea() + "亩"); System.out.println(t.getName() + "在" + c.getName() + "教授" + t.getCurriculum()); System.out.println( s.getName1() + "就读于" + s.getMajor() + s.getGrade() + "在上" + t.getName() + "的" + t.getCurriculum()); }
/** setup test */ public void setUp() { student = new Student(); songList = new SongList(); songList.add(new Song("Hotline Bling", "Drake", 2015, "Rap", 0)); student.setList(songList); student.setMajor(major); student.setHobby(hobby); student.setRegion(region); student.setHeard(num1); student.setLikes(num3); }
/** test set major */ public void testSetMajor() { student.setMajor(major); assertTrue(student.getMajor().equals(major)); }