2017-02-07 14:38:21 -05:00
|
|
|
package environment;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
import error.ErrorManager;
|
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
public class RuntimeEnvironmentTester {
|
2017-02-09 11:00:23 -05:00
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
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() {
|
2017-02-11 10:51:37 -05:00
|
|
|
indicatorSet = new HashSet<>();
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
@Test
|
|
|
|
public void assignInputName() {
|
2017-02-11 10:51:37 -05:00
|
|
|
environment.setInputName("test");
|
2017-02-09 11:00:23 -05:00
|
|
|
|
2017-02-11 10:51:37 -05:00
|
|
|
assertEquals("test", environment.getInputName());
|
2017-02-09 11:00:23 -05:00
|
|
|
}
|
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
@Test
|
|
|
|
public void assignInput() {
|
2017-02-11 10:51:37 -05:00
|
|
|
environment.setInput(System.in);
|
2017-02-07 14:38:21 -05:00
|
|
|
|
2017-02-11 10:51:37 -05:00
|
|
|
assertEquals(System.in, environment.getInput());
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void assignOutput() {
|
2017-02-11 10:51:37 -05:00
|
|
|
environment.setOutput(System.out);
|
2017-02-07 14:38:21 -05:00
|
|
|
|
2017-02-11 10:51:37 -05:00
|
|
|
assertEquals(System.out, environment.getOutput());
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void assignErrorOutput() {
|
2017-02-11 10:51:37 -05:00
|
|
|
environment.setErrorOutput(System.err);
|
2017-02-07 14:38:21 -05:00
|
|
|
|
2017-02-11 10:51:37 -05:00
|
|
|
assertEquals(System.err, environment.getErrorOutput());
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@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));
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
@Test
|
|
|
|
public void assignErrorManager() {
|
|
|
|
ErrorManager errorManager = new ErrorManager();
|
2017-02-11 10:51:37 -05:00
|
|
|
environment.setErrorManager(errorManager);
|
2017-02-09 11:00:23 -05:00
|
|
|
|
2017-02-11 10:51:37 -05:00
|
|
|
assertEquals(errorManager, environment.getErrorManager());
|
2017-02-09 11:00:23 -05:00
|
|
|
}
|
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|