From c8c9a477b758bae6bf6d9901ca2529adddd1df86 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Wed, 19 Jul 2017 15:23:15 -0400 Subject: [PATCH] Refactor common test set up and tear down code --- test/function/builtin/APPLYTest.java | 3 +- test/function/builtin/EVALTest.java | 3 +- test/function/builtin/EXITTest.java | 13 +++---- test/function/builtin/FUNCALLTest.java | 16 ++------- test/function/builtin/GENSYMTest.java | 3 +- test/function/builtin/LOADTest.java | 13 +++---- test/function/builtin/PRINTTest.java | 13 +++---- test/function/builtin/SETTest.java | 23 +++--------- .../function/builtin/SYMBOL_FUNCTIONTest.java | 16 ++------- test/function/builtin/cons/CONSTest.java | 3 +- test/function/builtin/cons/FIRSTTest.java | 3 +- test/function/builtin/cons/LENGTHTest.java | 3 +- test/function/builtin/cons/LISTTest.java | 4 ++- test/function/builtin/cons/RESTTest.java | 3 +- test/function/builtin/math/DIVIDETest.java | 3 +- test/function/builtin/math/MINUSTest.java | 3 +- test/function/builtin/math/MULTIPLYTest.java | 3 +- test/function/builtin/math/PLUSTest.java | 3 +- test/function/builtin/predicate/ATOMTest.java | 3 +- test/function/builtin/predicate/EQTest.java | 3 +- .../function/builtin/predicate/EQUALTest.java | 3 +- .../builtin/predicate/GENSYM_EQUALTest.java | 3 +- .../function/builtin/predicate/LISTPTest.java | 3 +- test/function/builtin/predicate/NULLTest.java | 3 +- .../builtin/predicate/NUMERIC_EQUALTest.java | 3 +- .../predicate/NUMERIC_GREATERTest.java | 3 +- .../builtin/predicate/NUMERIC_LESSTest.java | 3 +- test/function/builtin/special/ANDTest.java | 22 ++---------- test/function/builtin/special/CASETest.java | 22 ++---------- test/function/builtin/special/CONDTest.java | 3 +- .../builtin/special/DEFINE_SPECIALTest.java | 16 ++++----- .../builtin/special/DEFMACROTest.java | 16 ++++----- test/function/builtin/special/DEFUNTest.java | 21 ++++++----- test/function/builtin/special/IFTest.java | 22 ++---------- test/function/builtin/special/LAMBDATest.java | 3 +- test/function/builtin/special/LETTest.java | 22 ++---------- .../builtin/special/LET_STARTest.java | 22 ++---------- test/function/builtin/special/ORTest.java | 22 ++---------- test/function/builtin/special/PROGNTest.java | 4 ++- test/function/builtin/special/QUOTETest.java | 3 +- test/function/builtin/special/SETQTest.java | 23 +++--------- test/testutil/SymbolAndFunctionCleaner.java | 35 +++++++++++++++++++ 42 files changed, 166 insertions(+), 248 deletions(-) create mode 100644 test/testutil/SymbolAndFunctionCleaner.java diff --git a/test/function/builtin/APPLYTest.java b/test/function/builtin/APPLYTest.java index 5d1c9df..7a257a8 100644 --- a/test/function/builtin/APPLYTest.java +++ b/test/function/builtin/APPLYTest.java @@ -8,8 +8,9 @@ import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedFunctionException; import sexpression.Cons; +import testutil.SymbolAndFunctionCleaner; -public class APPLYTest { +public class APPLYTest extends SymbolAndFunctionCleaner { @Test public void applyWithSymbol() { diff --git a/test/function/builtin/EVALTest.java b/test/function/builtin/EVALTest.java index 70daedf..e199588 100644 --- a/test/function/builtin/EVALTest.java +++ b/test/function/builtin/EVALTest.java @@ -10,8 +10,9 @@ import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.BackquoteEvaluator.AtSignNotInCommaException; import function.builtin.EVAL.*; +import testutil.SymbolAndFunctionCleaner; -public class EVALTest { +public class EVALTest extends SymbolAndFunctionCleaner { @Test public void evalNumber() { diff --git a/test/function/builtin/EXITTest.java b/test/function/builtin/EXITTest.java index c739c55..5795e14 100644 --- a/test/function/builtin/EXITTest.java +++ b/test/function/builtin/EXITTest.java @@ -5,12 +5,13 @@ import static testutil.TestUtilities.evaluateString; import java.util.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import function.ArgumentValidator.TooManyArgumentsException; +import testutil.SymbolAndFunctionCleaner; -public class EXITTest { +public class EXITTest extends SymbolAndFunctionCleaner { private static final String TERMINATED = "terminated"; private RuntimeEnvironment environment; @@ -28,15 +29,15 @@ public class EXITTest { assertFalse(indicatorSet.contains(TERMINATED)); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { indicatorSet = new HashSet<>(); environment.reset(); environment.setTerminationFunction(() -> indicatorSet.add(TERMINATED)); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); } diff --git a/test/function/builtin/FUNCALLTest.java b/test/function/builtin/FUNCALLTest.java index 02ab7e7..577bf9f 100644 --- a/test/function/builtin/FUNCALLTest.java +++ b/test/function/builtin/FUNCALLTest.java @@ -1,23 +1,13 @@ package function.builtin; -import static table.FunctionTable.resetFunctionTable; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.TooFewArgumentsException; +import testutil.SymbolAndFunctionCleaner; -public class FUNCALLTest { - - @Before - public void setUp() { - resetFunctionTable(); - } - - @After - public void tearDown() { - resetFunctionTable(); - } +public class FUNCALLTest extends SymbolAndFunctionCleaner { @Test public void funcallWithNumbers() { diff --git a/test/function/builtin/GENSYMTest.java b/test/function/builtin/GENSYMTest.java index a716584..2fb496c 100644 --- a/test/function/builtin/GENSYMTest.java +++ b/test/function/builtin/GENSYMTest.java @@ -7,9 +7,10 @@ import static testutil.TypeAssertions.assertSymbol; import org.junit.Test; import function.ArgumentValidator.TooManyArgumentsException; +import testutil.SymbolAndFunctionCleaner; import token.TokenFactory.BadCharacterException; -public class GENSYMTest { +public class GENSYMTest extends SymbolAndFunctionCleaner { @Test public void gensymCreatesSymbol() { diff --git a/test/function/builtin/LOADTest.java b/test/function/builtin/LOADTest.java index 585528c..dd6730e 100644 --- a/test/function/builtin/LOADTest.java +++ b/test/function/builtin/LOADTest.java @@ -6,13 +6,14 @@ import static testutil.TypeAssertions.*; import java.io.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import error.ErrorManager; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class LOADTest { +public class LOADTest extends SymbolAndFunctionCleaner { private ByteArrayOutputStream outputStream; private ByteArrayOutputStream errorOutputStream; @@ -37,8 +38,8 @@ public class LOADTest { assertTrue(outputStream.toByteArray().length == 0); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { outputStream = new ByteArrayOutputStream(); errorOutputStream = new ByteArrayOutputStream(); @@ -51,8 +52,8 @@ public class LOADTest { environment.setErrorOutputDecorator(s -> s); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); } diff --git a/test/function/builtin/PRINTTest.java b/test/function/builtin/PRINTTest.java index edf2564..dff48fe 100644 --- a/test/function/builtin/PRINTTest.java +++ b/test/function/builtin/PRINTTest.java @@ -6,12 +6,13 @@ import static testutil.TestUtilities.evaluateString; import java.io.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class PRINTTest { +public class PRINTTest extends SymbolAndFunctionCleaner { private RuntimeEnvironment environment; private ByteArrayOutputStream outputStream; @@ -24,15 +25,15 @@ public class PRINTTest { assertEquals(expected, outputStream.toString()); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { outputStream = new ByteArrayOutputStream(); environment.reset(); environment.setOutput(new PrintStream(outputStream)); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); } diff --git a/test/function/builtin/SETTest.java b/test/function/builtin/SETTest.java index 9e27296..8ae482f 100644 --- a/test/function/builtin/SETTest.java +++ b/test/function/builtin/SETTest.java @@ -3,30 +3,15 @@ package function.builtin; import static org.junit.Assert.assertNull; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.LispNumber; -import table.*; +import table.SymbolTable; +import testutil.SymbolAndFunctionCleaner; -public class SETTest { - - private ExecutionContext executionContext; - - public SETTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class SETTest extends SymbolAndFunctionCleaner { @Test public void set() { diff --git a/test/function/builtin/SYMBOL_FUNCTIONTest.java b/test/function/builtin/SYMBOL_FUNCTIONTest.java index b161b70..174190a 100644 --- a/test/function/builtin/SYMBOL_FUNCTIONTest.java +++ b/test/function/builtin/SYMBOL_FUNCTIONTest.java @@ -3,25 +3,15 @@ package function.builtin; import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import static sexpression.Nil.NIL; -import static table.FunctionTable.resetFunctionTable; import static testutil.TestUtilities.evaluateString; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.SYMBOL_FUNCTION.UndefinedSymbolFunctionException; +import testutil.SymbolAndFunctionCleaner; -public class SYMBOL_FUNCTIONTest { - - @Before - public void setUp() { - resetFunctionTable(); - } - - @After - public void tearDown() { - resetFunctionTable(); - } +public class SYMBOL_FUNCTIONTest extends SymbolAndFunctionCleaner { @Test public void symbolFunction_BuiltInFunction() { diff --git a/test/function/builtin/cons/CONSTest.java b/test/function/builtin/cons/CONSTest.java index dba2a1c..a524340 100644 --- a/test/function/builtin/cons/CONSTest.java +++ b/test/function/builtin/cons/CONSTest.java @@ -6,8 +6,9 @@ import org.junit.Test; import function.ArgumentValidator.*; import sexpression.*; +import testutil.SymbolAndFunctionCleaner; -public class CONSTest { +public class CONSTest extends SymbolAndFunctionCleaner { @Test public void consWithNilValues() { diff --git a/test/function/builtin/cons/FIRSTTest.java b/test/function/builtin/cons/FIRSTTest.java index 7491fb1..cf51063 100644 --- a/test/function/builtin/cons/FIRSTTest.java +++ b/test/function/builtin/cons/FIRSTTest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class FIRSTTest { +public class FIRSTTest extends SymbolAndFunctionCleaner { @Test public void firstOfNil() { diff --git a/test/function/builtin/cons/LENGTHTest.java b/test/function/builtin/cons/LENGTHTest.java index 16fa3d4..749d04c 100644 --- a/test/function/builtin/cons/LENGTHTest.java +++ b/test/function/builtin/cons/LENGTHTest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class LENGTHTest { +public class LENGTHTest extends SymbolAndFunctionCleaner { @Test public void lengthOfNil() { diff --git a/test/function/builtin/cons/LISTTest.java b/test/function/builtin/cons/LISTTest.java index 4711eb5..675b22d 100644 --- a/test/function/builtin/cons/LISTTest.java +++ b/test/function/builtin/cons/LISTTest.java @@ -5,7 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; -public class LISTTest { +import testutil.SymbolAndFunctionCleaner; + +public class LISTTest extends SymbolAndFunctionCleaner { @Test public void listWithNoArguments() { diff --git a/test/function/builtin/cons/RESTTest.java b/test/function/builtin/cons/RESTTest.java index 78e3d40..dec352c 100644 --- a/test/function/builtin/cons/RESTTest.java +++ b/test/function/builtin/cons/RESTTest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class RESTTest { +public class RESTTest extends SymbolAndFunctionCleaner { @Test public void restOfNil() { diff --git a/test/function/builtin/math/DIVIDETest.java b/test/function/builtin/math/DIVIDETest.java index 9d55b3a..104045d 100644 --- a/test/function/builtin/math/DIVIDETest.java +++ b/test/function/builtin/math/DIVIDETest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class DIVIDETest { +public class DIVIDETest extends SymbolAndFunctionCleaner { @Test public void divideWithOne() { diff --git a/test/function/builtin/math/MINUSTest.java b/test/function/builtin/math/MINUSTest.java index bdc71fd..d5ef079 100644 --- a/test/function/builtin/math/MINUSTest.java +++ b/test/function/builtin/math/MINUSTest.java @@ -6,8 +6,9 @@ import org.junit.Test; import function.ArgumentValidator.*; import sexpression.LispNumber; +import testutil.SymbolAndFunctionCleaner; -public class MINUSTest { +public class MINUSTest extends SymbolAndFunctionCleaner { @Test public void minusWithOneNumber() { diff --git a/test/function/builtin/math/MULTIPLYTest.java b/test/function/builtin/math/MULTIPLYTest.java index 0048303..9da264c 100644 --- a/test/function/builtin/math/MULTIPLYTest.java +++ b/test/function/builtin/math/MULTIPLYTest.java @@ -6,8 +6,9 @@ import org.junit.Test; import function.ArgumentValidator.BadArgumentTypeException; import sexpression.LispNumber; +import testutil.SymbolAndFunctionCleaner; -public class MULTIPLYTest { +public class MULTIPLYTest extends SymbolAndFunctionCleaner { @Test public void multiplyWithNoArguments() { diff --git a/test/function/builtin/math/PLUSTest.java b/test/function/builtin/math/PLUSTest.java index 3290cae..1d850d9 100644 --- a/test/function/builtin/math/PLUSTest.java +++ b/test/function/builtin/math/PLUSTest.java @@ -6,8 +6,9 @@ import org.junit.Test; import function.ArgumentValidator.BadArgumentTypeException; import sexpression.LispNumber; +import testutil.SymbolAndFunctionCleaner; -public class PLUSTest { +public class PLUSTest extends SymbolAndFunctionCleaner { @Test public void plusWithNoArguments() { diff --git a/test/function/builtin/predicate/ATOMTest.java b/test/function/builtin/predicate/ATOMTest.java index 29fdde7..17329ef 100644 --- a/test/function/builtin/predicate/ATOMTest.java +++ b/test/function/builtin/predicate/ATOMTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class ATOMTest { +public class ATOMTest extends SymbolAndFunctionCleaner { @Test public void atomIsAtom() { diff --git a/test/function/builtin/predicate/EQTest.java b/test/function/builtin/predicate/EQTest.java index f284d97..2f6717f 100644 --- a/test/function/builtin/predicate/EQTest.java +++ b/test/function/builtin/predicate/EQTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class EQTest { +public class EQTest extends SymbolAndFunctionCleaner { @Test public void eqWithEqualAtoms() { diff --git a/test/function/builtin/predicate/EQUALTest.java b/test/function/builtin/predicate/EQUALTest.java index 0b99c96..d1cfafb 100644 --- a/test/function/builtin/predicate/EQUALTest.java +++ b/test/function/builtin/predicate/EQUALTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class EQUALTest { +public class EQUALTest extends SymbolAndFunctionCleaner { @Test public void equalWithTwoEqualAtoms() { diff --git a/test/function/builtin/predicate/GENSYM_EQUALTest.java b/test/function/builtin/predicate/GENSYM_EQUALTest.java index 55269b3..ab393aa 100644 --- a/test/function/builtin/predicate/GENSYM_EQUALTest.java +++ b/test/function/builtin/predicate/GENSYM_EQUALTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class GENSYM_EQUALTest { +public class GENSYM_EQUALTest extends SymbolAndFunctionCleaner { @Test public void gensymEqualWithTwoEqualAtoms() { diff --git a/test/function/builtin/predicate/LISTPTest.java b/test/function/builtin/predicate/LISTPTest.java index 46c2eb7..17b0282 100644 --- a/test/function/builtin/predicate/LISTPTest.java +++ b/test/function/builtin/predicate/LISTPTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class LISTPTest { +public class LISTPTest extends SymbolAndFunctionCleaner { @Test public void listpWithList() { diff --git a/test/function/builtin/predicate/NULLTest.java b/test/function/builtin/predicate/NULLTest.java index 7cf9bfa..a8b75b5 100644 --- a/test/function/builtin/predicate/NULLTest.java +++ b/test/function/builtin/predicate/NULLTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class NULLTest { +public class NULLTest extends SymbolAndFunctionCleaner { @Test public void nilIsNull() { diff --git a/test/function/builtin/predicate/NUMERIC_EQUALTest.java b/test/function/builtin/predicate/NUMERIC_EQUALTest.java index 29bf47d..1965463 100644 --- a/test/function/builtin/predicate/NUMERIC_EQUALTest.java +++ b/test/function/builtin/predicate/NUMERIC_EQUALTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class NUMERIC_EQUALTest { +public class NUMERIC_EQUALTest extends SymbolAndFunctionCleaner { @Test public void numericEqualWithOneNumber() { diff --git a/test/function/builtin/predicate/NUMERIC_GREATERTest.java b/test/function/builtin/predicate/NUMERIC_GREATERTest.java index 039796e..4aed1ae 100644 --- a/test/function/builtin/predicate/NUMERIC_GREATERTest.java +++ b/test/function/builtin/predicate/NUMERIC_GREATERTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class NUMERIC_GREATERTest { +public class NUMERIC_GREATERTest extends SymbolAndFunctionCleaner { @Test public void greaterThanWithOneNumber_ReturnsT() { diff --git a/test/function/builtin/predicate/NUMERIC_LESSTest.java b/test/function/builtin/predicate/NUMERIC_LESSTest.java index 03156a2..f2ba9da 100644 --- a/test/function/builtin/predicate/NUMERIC_LESSTest.java +++ b/test/function/builtin/predicate/NUMERIC_LESSTest.java @@ -6,8 +6,9 @@ import static testutil.TypeAssertions.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class NUMERIC_LESSTest { +public class NUMERIC_LESSTest extends SymbolAndFunctionCleaner { @Test public void lessThanWithOneNumber_ReturnsT() { diff --git a/test/function/builtin/special/ANDTest.java b/test/function/builtin/special/ANDTest.java index 3f28446..05d8f84 100644 --- a/test/function/builtin/special/ANDTest.java +++ b/test/function/builtin/special/ANDTest.java @@ -3,29 +3,13 @@ package function.builtin.special; import static testutil.TestUtilities.*; import static testutil.TypeAssertions.*; -import org.junit.*; +import org.junit.Test; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.LispNumber; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class ANDTest { - - private ExecutionContext executionContext; - - public ANDTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class ANDTest extends SymbolAndFunctionCleaner { @Test public void andByItself() { diff --git a/test/function/builtin/special/CASETest.java b/test/function/builtin/special/CASETest.java index 6ed5cd6..69bd42b 100644 --- a/test/function/builtin/special/CASETest.java +++ b/test/function/builtin/special/CASETest.java @@ -2,28 +2,12 @@ package function.builtin.special; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class CASETest { - - private ExecutionContext executionContext; - - public CASETest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class CASETest extends SymbolAndFunctionCleaner { @Test public void caseWithKeyOnly() { diff --git a/test/function/builtin/special/CONDTest.java b/test/function/builtin/special/CONDTest.java index e7c9742..8863e9c 100644 --- a/test/function/builtin/special/CONDTest.java +++ b/test/function/builtin/special/CONDTest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class CONDTest { +public class CONDTest extends SymbolAndFunctionCleaner { @Test public void condWithNoArguments() { diff --git a/test/function/builtin/special/DEFINE_SPECIALTest.java b/test/function/builtin/special/DEFINE_SPECIALTest.java index 3cd2dfa..a137fb8 100644 --- a/test/function/builtin/special/DEFINE_SPECIALTest.java +++ b/test/function/builtin/special/DEFINE_SPECIALTest.java @@ -1,19 +1,19 @@ package function.builtin.special; import static org.junit.Assert.assertTrue; -import static table.FunctionTable.resetFunctionTable; import static testutil.TestUtilities.*; import java.io.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import error.ErrorManager; import function.ArgumentValidator.*; import function.UserDefinedFunction.IllegalKeywordRestPositionException; +import testutil.SymbolAndFunctionCleaner; -public class DEFINE_SPECIALTest { +public class DEFINE_SPECIALTest extends SymbolAndFunctionCleaner { private ByteArrayOutputStream outputStream; private RuntimeEnvironment environment; @@ -26,21 +26,19 @@ public class DEFINE_SPECIALTest { assertTrue(outputStream.toByteArray().length > 0); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { outputStream = new ByteArrayOutputStream(); environment.reset(); environment.setOutput(new PrintStream(outputStream)); environment.setErrorManager(new ErrorManager()); environment.setWarningOutputDecorator(s -> s); - resetFunctionTable(); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); - resetFunctionTable(); } @Test diff --git a/test/function/builtin/special/DEFMACROTest.java b/test/function/builtin/special/DEFMACROTest.java index 46d2bd1..ba4ba9b 100644 --- a/test/function/builtin/special/DEFMACROTest.java +++ b/test/function/builtin/special/DEFMACROTest.java @@ -1,19 +1,19 @@ package function.builtin.special; import static org.junit.Assert.assertTrue; -import static table.FunctionTable.resetFunctionTable; import static testutil.TestUtilities.*; import java.io.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import error.ErrorManager; import function.ArgumentValidator.*; import function.UserDefinedFunction.IllegalKeywordRestPositionException; +import testutil.SymbolAndFunctionCleaner; -public class DEFMACROTest { +public class DEFMACROTest extends SymbolAndFunctionCleaner { private ByteArrayOutputStream outputStream; private RuntimeEnvironment environment; @@ -26,21 +26,19 @@ public class DEFMACROTest { assertTrue(outputStream.toByteArray().length > 0); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { outputStream = new ByteArrayOutputStream(); environment.reset(); environment.setOutput(new PrintStream(outputStream)); environment.setErrorManager(new ErrorManager()); environment.setWarningOutputDecorator(s -> s); - resetFunctionTable(); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); - resetFunctionTable(); } @Test diff --git a/test/function/builtin/special/DEFUNTest.java b/test/function/builtin/special/DEFUNTest.java index d0db053..979938a 100644 --- a/test/function/builtin/special/DEFUNTest.java +++ b/test/function/builtin/special/DEFUNTest.java @@ -1,19 +1,19 @@ package function.builtin.special; import static org.junit.Assert.assertTrue; -import static table.FunctionTable.resetFunctionTable; import static testutil.TestUtilities.*; import java.io.*; -import org.junit.*; +import org.junit.Test; import environment.RuntimeEnvironment; import error.ErrorManager; import function.ArgumentValidator.*; import function.UserDefinedFunction.IllegalKeywordRestPositionException; +import testutil.SymbolAndFunctionCleaner; -public class DEFUNTest { +public class DEFUNTest extends SymbolAndFunctionCleaner { private ByteArrayOutputStream outputStream; private RuntimeEnvironment environment; @@ -26,21 +26,19 @@ public class DEFUNTest { assertTrue(outputStream.toByteArray().length > 0); } - @Before - public void setUp() { + @Override + public void additionalSetUp() { outputStream = new ByteArrayOutputStream(); environment.reset(); environment.setOutput(new PrintStream(outputStream)); environment.setErrorManager(new ErrorManager()); environment.setWarningOutputDecorator(s -> s); - resetFunctionTable(); } - @After - public void tearDown() { + @Override + public void additionalTearDown() { environment.reset(); - resetFunctionTable(); } @Test @@ -121,6 +119,11 @@ public class DEFUNTest { evaluateString("(defun f a ())"); } + @Test(expected = BadArgumentTypeException.class) + public void defunWithNonSymbolInLambdaList() { + evaluateString("(defun f (1) ())"); + } + @Test(expected = TooFewArgumentsException.class) public void defunWithTooFewArguments() { evaluateString("(defun f)"); diff --git a/test/function/builtin/special/IFTest.java b/test/function/builtin/special/IFTest.java index 58715af..b9eba13 100644 --- a/test/function/builtin/special/IFTest.java +++ b/test/function/builtin/special/IFTest.java @@ -3,29 +3,13 @@ package function.builtin.special; import static testutil.TestUtilities.evaluateString; import static testutil.TypeAssertions.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedSymbolException; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class IFTest { - - private ExecutionContext executionContext; - - public IFTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class IFTest extends SymbolAndFunctionCleaner { @Test public void ifWithOneExpression_ReturnsExpression() { diff --git a/test/function/builtin/special/LAMBDATest.java b/test/function/builtin/special/LAMBDATest.java index 7f1e7a6..0c2f496 100644 --- a/test/function/builtin/special/LAMBDATest.java +++ b/test/function/builtin/special/LAMBDATest.java @@ -10,8 +10,9 @@ import org.junit.Test; import function.ArgumentValidator.*; import sexpression.*; +import testutil.SymbolAndFunctionCleaner; -public class LAMBDATest { +public class LAMBDATest extends SymbolAndFunctionCleaner { @Test public void lambda() { diff --git a/test/function/builtin/special/LETTest.java b/test/function/builtin/special/LETTest.java index 0e3b115..5b34b38 100644 --- a/test/function/builtin/special/LETTest.java +++ b/test/function/builtin/special/LETTest.java @@ -3,30 +3,14 @@ package function.builtin.special; import static sexpression.Nil.NIL; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.*; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class LETTest { - - private ExecutionContext executionContext; - - public LETTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class LETTest extends SymbolAndFunctionCleaner { @Test public void simpleLet() { diff --git a/test/function/builtin/special/LET_STARTest.java b/test/function/builtin/special/LET_STARTest.java index 960d23a..c6d0c33 100644 --- a/test/function/builtin/special/LET_STARTest.java +++ b/test/function/builtin/special/LET_STARTest.java @@ -3,30 +3,14 @@ package function.builtin.special; import static sexpression.Nil.NIL; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.*; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class LET_STARTest { - - private ExecutionContext executionContext; - - public LET_STARTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class LET_STARTest extends SymbolAndFunctionCleaner { @Test public void simpleLet() { diff --git a/test/function/builtin/special/ORTest.java b/test/function/builtin/special/ORTest.java index b8f7bad..c3d56c3 100644 --- a/test/function/builtin/special/ORTest.java +++ b/test/function/builtin/special/ORTest.java @@ -3,29 +3,13 @@ package function.builtin.special; import static testutil.TestUtilities.*; import static testutil.TypeAssertions.*; -import org.junit.*; +import org.junit.Test; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.LispNumber; -import table.ExecutionContext; +import testutil.SymbolAndFunctionCleaner; -public class ORTest { - - private ExecutionContext executionContext; - - public ORTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class ORTest extends SymbolAndFunctionCleaner { @Test public void orByItself() { diff --git a/test/function/builtin/special/PROGNTest.java b/test/function/builtin/special/PROGNTest.java index dacae16..1496d09 100644 --- a/test/function/builtin/special/PROGNTest.java +++ b/test/function/builtin/special/PROGNTest.java @@ -5,7 +5,9 @@ import static testutil.TypeAssertions.assertNil; import org.junit.Test; -public class PROGNTest { +import testutil.SymbolAndFunctionCleaner; + +public class PROGNTest extends SymbolAndFunctionCleaner { @Test public void prognWithNoArguments() { diff --git a/test/function/builtin/special/QUOTETest.java b/test/function/builtin/special/QUOTETest.java index e0b163d..3a209d8 100644 --- a/test/function/builtin/special/QUOTETest.java +++ b/test/function/builtin/special/QUOTETest.java @@ -5,8 +5,9 @@ import static testutil.TestUtilities.*; import org.junit.Test; import function.ArgumentValidator.*; +import testutil.SymbolAndFunctionCleaner; -public class QUOTETest { +public class QUOTETest extends SymbolAndFunctionCleaner { @Test public void quoteSymbol() { diff --git a/test/function/builtin/special/SETQTest.java b/test/function/builtin/special/SETQTest.java index e2fb02c..83731f1 100644 --- a/test/function/builtin/special/SETQTest.java +++ b/test/function/builtin/special/SETQTest.java @@ -3,30 +3,15 @@ package function.builtin.special; import static org.junit.Assert.assertNull; import static testutil.TestUtilities.*; -import org.junit.*; +import org.junit.Test; import function.ArgumentValidator.*; import function.builtin.EVAL.UndefinedSymbolException; import sexpression.LispNumber; -import table.*; +import table.SymbolTable; +import testutil.SymbolAndFunctionCleaner; -public class SETQTest { - - private ExecutionContext executionContext; - - public SETQTest() { - this.executionContext = ExecutionContext.getInstance(); - } - - @Before - public void setUp() { - executionContext.clearContext(); - } - - @After - public void tearDown() { - executionContext.clearContext(); - } +public class SETQTest extends SymbolAndFunctionCleaner { @Test public void setq() { diff --git a/test/testutil/SymbolAndFunctionCleaner.java b/test/testutil/SymbolAndFunctionCleaner.java new file mode 100644 index 0000000..941485f --- /dev/null +++ b/test/testutil/SymbolAndFunctionCleaner.java @@ -0,0 +1,35 @@ +package testutil; + +import static table.FunctionTable.resetFunctionTable; + +import org.junit.*; + +import table.ExecutionContext; + +public abstract class SymbolAndFunctionCleaner { + + protected ExecutionContext executionContext; + + public SymbolAndFunctionCleaner() { + this.executionContext = ExecutionContext.getInstance(); + } + + @Before + public final void setUp() { + executionContext.clearContext(); + resetFunctionTable(); + additionalSetUp(); + } + + @After + public final void tearDown() { + executionContext.clearContext(); + resetFunctionTable(); + additionalTearDown(); + } + + public void additionalSetUp() {} + + public void additionalTearDown() {} + +}