From ce1547d71ad3ef715df782ec381cfc342b8698a9 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sat, 11 Feb 2017 10:51:37 -0500 Subject: [PATCH] Formatted and cleaned some code --- src/environment/RuntimeEnvironment.java | 8 +++---- src/token/TokenFactoryImpl.java | 2 +- .../environment/RuntimeEnvironmentTester.java | 22 +++++++++---------- test/error/ErrorManagerTester.java | 17 +++++++++----- test/function/builtin/LOADTester.java | 16 +++++++++----- test/function/builtin/PRINTTester.java | 2 +- .../function/builtin/special/DEFUNTester.java | 13 ++++++++--- 7 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/environment/RuntimeEnvironment.java b/src/environment/RuntimeEnvironment.java index 628e20a..de0030f 100644 --- a/src/environment/RuntimeEnvironment.java +++ b/src/environment/RuntimeEnvironment.java @@ -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; } diff --git a/src/token/TokenFactoryImpl.java b/src/token/TokenFactoryImpl.java index eb22e69..14c8a84 100644 --- a/src/token/TokenFactoryImpl.java +++ b/src/token/TokenFactoryImpl.java @@ -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) { diff --git a/test/environment/RuntimeEnvironmentTester.java b/test/environment/RuntimeEnvironmentTester.java index 0241c01..fa87a7c 100644 --- a/test/environment/RuntimeEnvironmentTester.java +++ b/test/environment/RuntimeEnvironmentTester.java @@ -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()); } } diff --git a/test/error/ErrorManagerTester.java b/test/error/ErrorManagerTester.java index 2882662..36929f3 100644 --- a/test/error/ErrorManagerTester.java +++ b/test/error/ErrorManagerTester.java @@ -19,11 +19,16 @@ public class ErrorManagerTester { private Set 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 diff --git a/test/function/builtin/LOADTester.java b/test/function/builtin/LOADTester.java index 4c37c8a..4dfff24 100644 --- a/test/function/builtin/LOADTester.java +++ b/test/function/builtin/LOADTester.java @@ -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 diff --git a/test/function/builtin/PRINTTester.java b/test/function/builtin/PRINTTester.java index dc7baea..2bce16d 100644 --- a/test/function/builtin/PRINTTester.java +++ b/test/function/builtin/PRINTTester.java @@ -21,7 +21,7 @@ public class PRINTTester { @Before public void setUp() { - this.outputStream = new ByteArrayOutputStream(); + outputStream = new ByteArrayOutputStream(); RuntimeEnvironment.getInstance().setOutput(new PrintStream(outputStream)); } diff --git a/test/function/builtin/special/DEFUNTester.java b/test/function/builtin/special/DEFUNTester.java index 49e36de..c3fae13 100644 --- a/test/function/builtin/special/DEFUNTester.java +++ b/test/function/builtin/special/DEFUNTester.java @@ -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(); }