Added unit tests for the RuntimeEnvironment
This commit is contained in:
parent
65069561b8
commit
b55738231c
|
@ -0,0 +1,64 @@
|
||||||
|
package environment;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class RuntimeEnvironmentTester {
|
||||||
|
|
||||||
|
private static final String TERMINATED_SUCCESSFULLY = "TERMINATED_SUCCESSFULLY";
|
||||||
|
private static final String TERMINATED_EXCEPTIONALLY = "TERMINATED_EXCEPTIONALLY";
|
||||||
|
|
||||||
|
private RuntimeEnvironment environment;
|
||||||
|
private Set<String> indicatorSet;
|
||||||
|
|
||||||
|
public RuntimeEnvironmentTester() {
|
||||||
|
this.environment = RuntimeEnvironment.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
this.indicatorSet = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assignInput() {
|
||||||
|
this.environment.setInput(System.in);
|
||||||
|
|
||||||
|
assertEquals(System.in, this.environment.getInput());
|
||||||
|
assertEquals(System.in.toString(), this.environment.getInputName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assignOutput() {
|
||||||
|
this.environment.setOutput(System.out);
|
||||||
|
|
||||||
|
assertEquals(System.out, this.environment.getOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assignErrorOutput() {
|
||||||
|
this.environment.setErrorOutput(System.err);
|
||||||
|
|
||||||
|
assertEquals(System.err, this.environment.getErrorOutput());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assignTerminationFunction() {
|
||||||
|
environment.setTerminationFunction(() -> indicatorSet.add(TERMINATED_SUCCESSFULLY));
|
||||||
|
environment.terminateSuccessfully();
|
||||||
|
|
||||||
|
assertTrue(indicatorSet.contains(TERMINATED_SUCCESSFULLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assignErrorTerminationFunction() {
|
||||||
|
environment.setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED_EXCEPTIONALLY));
|
||||||
|
environment.terminateExceptionally();
|
||||||
|
|
||||||
|
assertTrue(indicatorSet.contains(TERMINATED_EXCEPTIONALLY));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue