Skip to content
Snippets Groups Projects
Verified Commit 88897382 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Removed deprecated security manager from SortThreePairsTest

parent 16ee3e5a
No related branches found
No related tags found
No related merge requests found
package edu.unl.cse.soft160.sort_three_pairs;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.PrintStream;
import java.security.Permission;
import java.io.ByteArrayOutputStream;
import static org.junit.Assert.*;
......@@ -29,62 +26,6 @@ public class SortThreePairsTest {
return collector.toString();
}
@SuppressWarnings("serial")
protected static class ExitException extends SecurityException {
public final int status;
public ExitException(int status) {
super("Exit with status " + status);
this.status = status;
}
}
private static class TestingSecurityManager extends SecurityManager {
@Override
public void checkPermission(Permission perm) {
}
@Override
public void checkPermission(Permission perm, Object context) {
}
@Override
public void checkExit(int status) {
super.checkExit(status);
throw new ExitException(status);
}
}
@Before
public void setUp() throws SecurityException {
System.setSecurityManager(new TestingSecurityManager());
}
@After
public void tearDown() throws SecurityException {
System.setSecurityManager(null);
}
protected static String runMainForError(int expectedStatus, String... arguments) {
InputStream in = System.in;
PrintStream err = System.err;
System.setIn(new ByteArrayInputStream("".getBytes()));
ByteArrayOutputStream collector = new ByteArrayOutputStream();
System.setErr(new PrintStream(collector));
boolean exited = false;
try {
SortThreePairs.main(arguments);
} catch (ExitException expected) {
assertEquals(expectedStatus, expected.status);
exited = true;
} finally {
System.setIn(in);
System.setErr(err);
}
assertTrue(exited);
return collector.toString();
}
@Test
public void testZeros() {
assertEquals(assemble("(0.0, 0.0)", "(0.0, 0.0)", "(0.0, 0.0)"),
......@@ -156,12 +97,4 @@ public class SortThreePairsTest {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("1", "1", "0", "0", "2", "2"));
}
@Test
public void testTooFewArguments() {
assertEquals(
assemble("Sorts three points by their x coordinates, breaking ties using y coordinates.",
"Usage: java edu.unl.cse.soft160.sort_three_pairs.SortThreePairs [X0] [Y0] [X1] [Y1] [X2] [Y2]"),
runMainForError(1, "0", "0", "1", "1", "2", "2", "3"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment