Formatted and cleaned some code

This commit is contained in:
Mike Cifelli 2017-02-11 10:51:37 -05:00
parent 6fa132313d
commit ce1547d71a
7 changed files with 49 additions and 31 deletions

View File

@ -21,7 +21,7 @@ public class RuntimeEnvironment {
private ErrorManager errorManager; private ErrorManager errorManager;
private RuntimeEnvironment() {} private RuntimeEnvironment() {}
public void setInputName(String inputName) { public void setInputName(String inputName) {
this.inputName = inputName; this.inputName = inputName;
} }
@ -45,11 +45,11 @@ public class RuntimeEnvironment {
public void setErrorTerminationFunction(Runnable errorTerminationFunction) { public void setErrorTerminationFunction(Runnable errorTerminationFunction) {
this.errorTerminationFunction = errorTerminationFunction; this.errorTerminationFunction = errorTerminationFunction;
} }
public void setErrorManager(ErrorManager errorManager) { public void setErrorManager(ErrorManager errorManager) {
this.errorManager = errorManager; this.errorManager = errorManager;
} }
public String getInputName() { public String getInputName() {
return inputName; return inputName;
} }
@ -73,7 +73,7 @@ public class RuntimeEnvironment {
public void terminateExceptionally() { public void terminateExceptionally() {
errorTerminationFunction.run(); errorTerminationFunction.run();
} }
public ErrorManager getErrorManager() { public ErrorManager getErrorManager() {
return errorManager; return errorManager;
} }

View File

@ -10,7 +10,7 @@ public class TokenFactoryImpl implements TokenFactory {
public Token createToken(String text, FilePosition position) { public Token createToken(String text, FilePosition position) {
if (text.length() == 0) if (text.length() == 0)
throw new EmptyTokenTextException(position); throw new EmptyTokenTextException(position);
char firstCharacter = text.charAt(0); char firstCharacter = text.charAt(0);
switch (firstCharacter) { switch (firstCharacter) {

View File

@ -22,35 +22,35 @@ public class RuntimeEnvironmentTester {
@Before @Before
public void setUp() { public void setUp() {
this.indicatorSet = new HashSet<>(); indicatorSet = new HashSet<>();
} }
@Test @Test
public void assignInputName() { public void assignInputName() {
this.environment.setInputName("test"); environment.setInputName("test");
assertEquals("test", this.environment.getInputName()); assertEquals("test", environment.getInputName());
} }
@Test @Test
public void assignInput() { public void assignInput() {
this.environment.setInput(System.in); environment.setInput(System.in);
assertEquals(System.in, this.environment.getInput()); assertEquals(System.in, environment.getInput());
} }
@Test @Test
public void assignOutput() { public void assignOutput() {
this.environment.setOutput(System.out); environment.setOutput(System.out);
assertEquals(System.out, this.environment.getOutput()); assertEquals(System.out, environment.getOutput());
} }
@Test @Test
public void assignErrorOutput() { public void assignErrorOutput() {
this.environment.setErrorOutput(System.err); environment.setErrorOutput(System.err);
assertEquals(System.err, this.environment.getErrorOutput()); assertEquals(System.err, environment.getErrorOutput());
} }
@Test @Test
@ -72,9 +72,9 @@ public class RuntimeEnvironmentTester {
@Test @Test
public void assignErrorManager() { public void assignErrorManager() {
ErrorManager errorManager = new ErrorManager(); ErrorManager errorManager = new ErrorManager();
this.environment.setErrorManager(errorManager); environment.setErrorManager(errorManager);
assertEquals(errorManager, this.environment.getErrorManager()); assertEquals(errorManager, environment.getErrorManager());
} }
} }

View File

@ -19,11 +19,16 @@ public class ErrorManagerTester {
private Set<String> indicatorSet; private Set<String> indicatorSet;
private ByteArrayOutputStream errorOutputStream; private ByteArrayOutputStream errorOutputStream;
private ByteArrayOutputStream outputStream; private ByteArrayOutputStream outputStream;
private RuntimeEnvironment environment;
public ErrorManagerTester() {
this.environment = RuntimeEnvironment.getInstance();
}
private ErrorManager createErrorManagerWithIndicators() { private ErrorManager createErrorManagerWithIndicators() {
RuntimeEnvironment.getInstance().setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED)); environment.setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED));
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream)); environment.setErrorOutput(new PrintStream(errorOutputStream));
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); environment.setOutput(new PrintStream(outputStream));
return new ErrorManager(); return new ErrorManager();
} }
@ -71,9 +76,9 @@ public class ErrorManagerTester {
@Before @Before
public void setUp() { public void setUp() {
this.indicatorSet = new HashSet<>(); indicatorSet = new HashSet<>();
this.errorOutputStream = new ByteArrayOutputStream(); errorOutputStream = new ByteArrayOutputStream();
this.outputStream = new ByteArrayOutputStream(); outputStream = new ByteArrayOutputStream();
} }
@Test @Test

View File

@ -16,6 +16,11 @@ public class LOADTester {
private ByteArrayOutputStream outputStream; private ByteArrayOutputStream outputStream;
private ByteArrayOutputStream errorOutputStream; private ByteArrayOutputStream errorOutputStream;
private RuntimeEnvironment environment;
public LOADTester() {
this.environment = RuntimeEnvironment.getInstance();
}
private void assertWarningMessagePrinted() { private void assertWarningMessagePrinted() {
assertTrue(outputStream.toByteArray().length > 0); assertTrue(outputStream.toByteArray().length > 0);
@ -34,11 +39,12 @@ public class LOADTester {
@Before @Before
public void setUp() { public void setUp() {
this.outputStream = new ByteArrayOutputStream(); outputStream = new ByteArrayOutputStream();
this.errorOutputStream = new ByteArrayOutputStream(); errorOutputStream = new ByteArrayOutputStream();
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream));
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream)); environment.setOutput(new PrintStream(outputStream));
RuntimeEnvironment.getInstance().setErrorManager(new ErrorManager()); environment.setErrorOutput(new PrintStream(errorOutputStream));
environment.setErrorManager(new ErrorManager());
} }
@Test @Test

View File

@ -21,7 +21,7 @@ public class PRINTTester {
@Before @Before
public void setUp() { public void setUp() {
this.outputStream = new ByteArrayOutputStream(); outputStream = new ByteArrayOutputStream();
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream));
} }

View File

@ -15,6 +15,11 @@ import table.FunctionTable;
public class DEFUNTester { public class DEFUNTester {
private ByteArrayOutputStream outputStream; private ByteArrayOutputStream outputStream;
private RuntimeEnvironment environment;
public DEFUNTester() {
this.environment = RuntimeEnvironment.getInstance();
}
private void assertSomethingPrinted() { private void assertSomethingPrinted() {
assertTrue(outputStream.toByteArray().length > 0); assertTrue(outputStream.toByteArray().length > 0);
@ -22,9 +27,11 @@ public class DEFUNTester {
@Before @Before
public void setUp() { public void setUp() {
this.outputStream = new ByteArrayOutputStream(); outputStream = new ByteArrayOutputStream();
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream));
RuntimeEnvironment.getInstance().setErrorManager(new ErrorManager()); environment.setOutput(new PrintStream(outputStream));
environment.setErrorManager(new ErrorManager());
FunctionTable.reset(); FunctionTable.reset();
} }