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() {
|
|
|
|
this.indicatorSet = new HashSet<>();
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
@Test
|
|
|
|
public void assignInputName() {
|
|
|
|
this.environment.setInputName("test");
|
|
|
|
|
|
|
|
assertEquals("test", this.environment.getInputName());
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
@Test
|
|
|
|
public void assignInput() {
|
|
|
|
this.environment.setInput(System.in);
|
|
|
|
|
|
|
|
assertEquals(System.in, this.environment.getInput());
|
|
|
|
}
|
|
|
|
|
|
|
|
@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));
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
@Test
|
|
|
|
public void assignErrorManager() {
|
|
|
|
ErrorManager errorManager = new ErrorManager();
|
|
|
|
this.environment.setErrorManager(errorManager);
|
|
|
|
|
|
|
|
assertEquals(errorManager, this.environment.getErrorManager());
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:38:21 -05:00
|
|
|
}
|