mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-07 01:23:56 -05:00
Changed test methods
This commit is contained in:
@@ -1,31 +1,57 @@
|
||||
package com.mattrixwv.project_euler.problems;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.atMostOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.mattrixwv.Stopwatch;
|
||||
import com.mattrixwv.project_euler.exceptions.Unsolved;
|
||||
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
public abstract class BaseTest{
|
||||
@Spy
|
||||
protected Stopwatch timer;
|
||||
protected static String description;
|
||||
protected static String result;
|
||||
|
||||
public abstract void testDescription();
|
||||
public void testDescription(Problem problem){
|
||||
assertEquals(description, problem.getDescription());
|
||||
assertFalse(problem.getSolved());
|
||||
}
|
||||
|
||||
public abstract void testSolve();
|
||||
|
||||
protected void verifyProblem(Problem problem){
|
||||
public void testSolve(Problem problem){
|
||||
//Verify the results cannot be seen until the problem has been run
|
||||
assertThrows(Unsolved.class, () -> { problem.getResult(); });
|
||||
|
||||
problem.solve();
|
||||
|
||||
//Verify solved was set
|
||||
assertTrue(problem.getSolved());
|
||||
assertEquals(result, problem.getResult());
|
||||
//Verify timer function were called
|
||||
verify(timer, atLeastOnce()).start();
|
||||
verify(timer, atLeastOnce()).stop();
|
||||
}
|
||||
|
||||
protected void verifyProblemSecondRun(Problem problem){
|
||||
//Verify the problem won't be run again
|
||||
problem.solve();
|
||||
|
||||
//Verify solved is still set
|
||||
@@ -35,8 +61,16 @@ public abstract class BaseTest{
|
||||
verify(timer, atMostOnce()).stop();
|
||||
}
|
||||
|
||||
public void testReset(){
|
||||
//Verify timer was reset
|
||||
verify(timer, atLeastOnce()).reset();
|
||||
public abstract void testReset();
|
||||
public void testReset(Problem problem){
|
||||
assertTrue(problem.solved);
|
||||
|
||||
problem.reset();
|
||||
|
||||
//Verify solved was reset
|
||||
assertFalse(problem.getSolved());
|
||||
|
||||
//Verify the problem can be solved again
|
||||
testSolve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user