GoalComparator implements Comparator<TestFitnessFunction> { @Override public int compare(TestFitnessFunction o1, TestFitnessFunction o2) { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if(c1.equals(c2)) return o1.compareTo(o2); if(c1.equals(ExceptionCoverageTestFitness.class)) return -1; else if(c2.equals(ExceptionCoverageTestFitness.class)) return 1; if(c1.equals(MethodCoverageTestFitness.class)) return -1; else if(c2.equals(MethodCoverageTestFitness.class)) return 1; if(c1.equals(MethodNoExceptionCoverageTestFitness.class)) return -1; else if(c2.equals(MethodNoExceptionCoverageTestFitness.class)) return 1; if(c1.equals(OutputCoverageTestFitness.class)) return -1; else if(c2.equals(OutputCoverageTestFitness.class)) return 1; if(c1.equals(InputCoverageTestFitness.class)) return -1; else if(c2.equals(InputCoverageTestFitness.class)) return 1; return 0; }  @Override int compare(TestFitnessFunction o1, TestFitnessFunction o2);  }
@Test public void testCompareEqual() { GoalComparator comparator = new GoalComparator(); ExceptionCoverageTestFitness goal1 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT); ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT); assertEquals(0, comparator.compare(goal1, goal2)); }
@Test public void testCompareExceptionMethod() { GoalComparator comparator = new GoalComparator(); MethodCoverageTestFitness goal1 = new MethodCoverageTestFitness("FooClass", "toString()"); ExceptionCoverageTestFitness goal2 = new ExceptionCoverageTestFitness("FooClass", "toString()", MockArithmeticException.class, ExceptionCoverageTestFitness.ExceptionType.EXPLICIT); assertEquals(1, comparator.compare(goal1, goal2)); }