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

View File

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

View File

@ -22,35 +22,35 @@ public class RuntimeEnvironmentTester {
@Before
public void setUp() {
this.indicatorSet = new HashSet<>();
indicatorSet = new HashSet<>();
}
@Test
public void assignInputName() {
this.environment.setInputName("test");
environment.setInputName("test");
assertEquals("test", this.environment.getInputName());
assertEquals("test", environment.getInputName());
}
@Test
public void assignInput() {
this.environment.setInput(System.in);
environment.setInput(System.in);
assertEquals(System.in, this.environment.getInput());
assertEquals(System.in, environment.getInput());
}
@Test
public void assignOutput() {
this.environment.setOutput(System.out);
environment.setOutput(System.out);
assertEquals(System.out, this.environment.getOutput());
assertEquals(System.out, environment.getOutput());
}
@Test
public void assignErrorOutput() {
this.environment.setErrorOutput(System.err);
environment.setErrorOutput(System.err);
assertEquals(System.err, this.environment.getErrorOutput());
assertEquals(System.err, environment.getErrorOutput());
}
@Test
@ -72,9 +72,9 @@ public class RuntimeEnvironmentTester {
@Test
public void assignErrorManager() {
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 ByteArrayOutputStream errorOutputStream;
private ByteArrayOutputStream outputStream;
private RuntimeEnvironment environment;
public ErrorManagerTester() {
this.environment = RuntimeEnvironment.getInstance();
}
private ErrorManager createErrorManagerWithIndicators() {
RuntimeEnvironment.getInstance().setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED));
RuntimeEnvironment.getInstance().setErrorOutput(new PrintStream(errorOutputStream));
RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream));
environment.setErrorTerminationFunction(() -> indicatorSet.add(TERMINATED));
environment.setErrorOutput(new PrintStream(errorOutputStream));
environment.setOutput(new PrintStream(outputStream));
return new ErrorManager();
}
@ -71,9 +76,9 @@ public class ErrorManagerTester {
@Before
public void setUp() {
this.indicatorSet = new HashSet<>();
this.errorOutputStream = new ByteArrayOutputStream();
this.outputStream = new ByteArrayOutputStream();
indicatorSet = new HashSet<>();
errorOutputStream = new ByteArrayOutputStream();
outputStream = new ByteArrayOutputStream();
}
@Test

View File

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

View File

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

View File

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