2016-12-16 12:31:16 -05:00
|
|
|
package error;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2016-12-16 13:12:13 -05:00
|
|
|
import org.junit.Before;
|
2016-12-16 12:31:16 -05:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class ErrorManagerTester {
|
|
|
|
|
|
|
|
private static final String TERMINATED = "terminated";
|
|
|
|
private static final String MESSAGE = "message";
|
|
|
|
|
2016-12-16 13:12:13 -05:00
|
|
|
private Set<String> indicatorSet;
|
|
|
|
|
|
|
|
private ErrorManager createErrorManagerWithIndicators() {
|
2016-12-19 11:38:14 -05:00
|
|
|
return new ErrorManager(() -> indicatorSet.add(TERMINATED), (String) -> indicatorSet.add(MESSAGE));
|
2016-12-16 12:31:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private LispException createLispException(int severity) {
|
|
|
|
return new LispException() {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSeverity() {
|
|
|
|
return severity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getMessage() {
|
|
|
|
return MESSAGE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-12-16 14:15:29 -05:00
|
|
|
|
2016-12-16 13:12:13 -05:00
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
this.indicatorSet = new HashSet<>();
|
|
|
|
}
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void givenCriticalExceptionSeverity_RunsProvidedTerminationFunction() {
|
2016-12-16 13:12:13 -05:00
|
|
|
ErrorManager errorManager = createErrorManagerWithIndicators();
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
errorManager.generateError(createLispException(ErrorManager.CRITICAL_LEVEL));
|
|
|
|
assertTrue(indicatorSet.contains(TERMINATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void givenNonCriticalExceptionSeverity_DoesNotRunProvidedTerminationFunction() {
|
2016-12-16 13:12:13 -05:00
|
|
|
ErrorManager errorManager = createErrorManagerWithIndicators();
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
errorManager.generateError(createLispException(0));
|
|
|
|
assertFalse(indicatorSet.contains(TERMINATED));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void noMessageDisplayedBeforeError() {
|
2016-12-16 13:12:13 -05:00
|
|
|
createErrorManagerWithIndicators();
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
assertFalse(indicatorSet.contains(TERMINATED));
|
|
|
|
assertFalse(indicatorSet.contains(MESSAGE));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void usesOutputFunctionToDisplayMessages_NoTermination() {
|
2016-12-16 13:12:13 -05:00
|
|
|
ErrorManager errorManager = createErrorManagerWithIndicators();
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
errorManager.generateError(createLispException(0));
|
|
|
|
assertFalse(indicatorSet.contains(TERMINATED));
|
|
|
|
assertTrue(indicatorSet.contains(MESSAGE));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void usesOutputFunctionToDisplayMessages_WithTermination() {
|
2016-12-16 13:12:13 -05:00
|
|
|
ErrorManager errorManager = createErrorManagerWithIndicators();
|
2016-12-16 12:31:16 -05:00
|
|
|
|
|
|
|
errorManager.generateError(createLispException(ErrorManager.CRITICAL_LEVEL));
|
|
|
|
assertTrue(indicatorSet.contains(TERMINATED));
|
|
|
|
assertTrue(indicatorSet.contains(MESSAGE));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|