package function.builtin; import static org.junit.Assert.*; import static testutil.TestUtilities.evaluateString; import java.util.*; import org.junit.*; import environment.RuntimeEnvironment; import function.ArgumentValidator.TooManyArgumentsException; public class EXITTester { private static final String TERMINATED = "terminated"; private Set indicatorSet; private void assertTerminated() { assertTrue(indicatorSet.contains(TERMINATED)); } private void assertNotTerminated() { assertFalse(indicatorSet.contains(TERMINATED)); } @Before public void setUp() { indicatorSet = new HashSet<>(); RuntimeEnvironment.getInstance().setTerminationFunction(() -> indicatorSet.add(TERMINATED)); } @Test public void exitWorks() { evaluateString("(exit)"); assertTerminated(); } @Test public void exitNotCalled_IndicatorSetIsClean() { assertNotTerminated(); } @Test(expected = TooManyArgumentsException.class) public void exitWithTooManyArguments() { evaluateString("(exit 1)"); } }