From ba53448c9d8e8e8da55472185a93b67ba6913c66 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Fri, 3 Mar 2017 12:07:23 -0500 Subject: [PATCH] Exception checking unit tests were refactored --- test/function/ArgumentValidatorTester.java | 8 +--- test/function/builtin/EVALTester.java | 7 ++- .../builtin/SYMBOL_FUNCTIONTester.java | 4 +- .../LispInterpreterBuilderTester.java | 4 +- test/parser/LispParserTester.java | 45 +++---------------- test/sexpression/SExpressionTester.java | 12 +---- 6 files changed, 20 insertions(+), 60 deletions(-) diff --git a/test/function/ArgumentValidatorTester.java b/test/function/ArgumentValidatorTester.java index 2b7a8e6..4239e61 100644 --- a/test/function/ArgumentValidatorTester.java +++ b/test/function/ArgumentValidatorTester.java @@ -169,16 +169,10 @@ public class ArgumentValidatorTester { } @Test - public void DottedArgumentListException_HasCorrectSeverity() { + public void dottedArgumentListException_HasCorrectAttributes() { DottedArgumentListException e = new DottedArgumentListException("TEST", NIL); assertEquals(ERROR, e.getSeverity()); - } - - @Test - public void dottedArgumentListException_HasMessageText() { - DottedArgumentListException e = new DottedArgumentListException("TEST", NIL); - assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } diff --git a/test/function/builtin/EVALTester.java b/test/function/builtin/EVALTester.java index 6635a44..f01f8e9 100644 --- a/test/function/builtin/EVALTester.java +++ b/test/function/builtin/EVALTester.java @@ -1,5 +1,6 @@ package function.builtin; +import static error.ErrorManager.Severity.ERROR; import static function.builtin.EVAL.lookupSymbol; import static org.junit.Assert.*; import static sexpression.Nil.NIL; @@ -81,17 +82,19 @@ public class EVALTester { } @Test - public void undefinedFunctionException_HasMessageText() { + public void undefinedFunctionException_HasCorrectAttributes() { UndefinedFunctionException e = new UndefinedFunctionException(NIL); + assertEquals(ERROR, e.getSeverity()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } @Test - public void undefinedSymbolException_HasMessageText() { + public void undefinedSymbolException_HasCorrectAttributes() { UndefinedSymbolException e = new UndefinedSymbolException(NIL); + assertEquals(ERROR, e.getSeverity()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } diff --git a/test/function/builtin/SYMBOL_FUNCTIONTester.java b/test/function/builtin/SYMBOL_FUNCTIONTester.java index 5321d14..ed3d6c4 100644 --- a/test/function/builtin/SYMBOL_FUNCTIONTester.java +++ b/test/function/builtin/SYMBOL_FUNCTIONTester.java @@ -1,5 +1,6 @@ package function.builtin; +import static error.ErrorManager.Severity.ERROR; import static org.junit.Assert.*; import static sexpression.Nil.NIL; import static testutil.TestUtilities.evaluateString; @@ -68,9 +69,10 @@ public class SYMBOL_FUNCTIONTester { } @Test - public void undefinedSymbolFunctionException_HasMessageText() { + public void undefinedSymbolFunctionException_HasCorrectAttributes() { UndefinedSymbolFunctionException e = new UndefinedSymbolFunctionException(NIL); + assertEquals(ERROR, e.getSeverity()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } diff --git a/test/interpreter/LispInterpreterBuilderTester.java b/test/interpreter/LispInterpreterBuilderTester.java index e0fa3df..5fd8aa5 100644 --- a/test/interpreter/LispInterpreterBuilderTester.java +++ b/test/interpreter/LispInterpreterBuilderTester.java @@ -1,5 +1,6 @@ package interpreter; +import static error.ErrorManager.Severity.CRITICAL; import static org.junit.Assert.*; import java.io.*; @@ -69,9 +70,10 @@ public class LispInterpreterBuilderTester { } @Test - public void interpreterAlreadyBuiltException_HasMessage() { + public void interpreterAlreadyBuiltException_HasCorrectAttributes() { InterpreterAlreadyBuiltException e = new InterpreterAlreadyBuiltException(); + assertEquals(CRITICAL, e.getSeverity()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().length() > 0); } diff --git a/test/parser/LispParserTester.java b/test/parser/LispParserTester.java index 1c438fb..ebe27ce 100644 --- a/test/parser/LispParserTester.java +++ b/test/parser/LispParserTester.java @@ -182,19 +182,7 @@ public class LispParserTester { } @Test - public void givenBadToken_ExceptionHasCorrectSeverity() { - String input = "["; - LispParser parser = createLispParser(input); - - try { - parser.getNextSExpression(); - } catch (BadCharacterException e) { - assertEquals(ERROR, e.getSeverity()); - } - } - - @Test - public void givenBadToken_ExceptionHasMessageText() { + public void givenBadToken_ExceptionHasCorrectAttributes() { String input = "["; LispParser parser = createLispParser(input); @@ -203,6 +191,7 @@ public class LispParserTester { } catch (BadCharacterException e) { String message = e.getMessage(); + assertEquals(ERROR, e.getSeverity()); assertNotNull(message); assertTrue(message.length() > 0); } @@ -225,19 +214,7 @@ public class LispParserTester { } @Test - public void givenUnterminatedList_ExceptionHasCorrectSeverity() { - String input = "(bad list"; - LispParser parser = createLispParser(input); - - try { - parser.getNextSExpression(); - } catch (EofEncounteredException e) { - assertEquals(ERROR, e.getSeverity()); - } - } - - @Test - public void givenUnterminatedList_ExceptionHasMessage() { + public void givenUnterminatedList_ExceptionHasCorrectAttributes() { String input = "(bad list"; LispParser parser = createLispParser(input); @@ -246,6 +223,7 @@ public class LispParserTester { } catch (EofEncounteredException e) { String message = e.getMessage(); + assertEquals(ERROR, e.getSeverity()); assertNotNull(message); assertTrue(message.length() > 0); } @@ -260,19 +238,7 @@ public class LispParserTester { } @Test - public void givenUnmatchedRightParenthesis_ExceptionHasCorrectSeverity() { - String input = ")"; - LispParser parser = createLispParser(input); - - try { - parser.getNextSExpression(); - } catch (StartsWithRightParenthesisException e) { - assertEquals(ERROR, e.getSeverity()); - } - } - - @Test - public void givenUnmatchedRightParenthesis_ExceptionHasMessage() { + public void givenUnmatchedRightParenthesis_ExceptionHasCorrectAttributes() { String input = ")"; LispParser parser = createLispParser(input); @@ -281,6 +247,7 @@ public class LispParserTester { } catch (StartsWithRightParenthesisException e) { String message = e.getMessage(); + assertEquals(ERROR, e.getSeverity()); assertNotNull(message); assertTrue(message.length() > 0); } diff --git a/test/sexpression/SExpressionTester.java b/test/sexpression/SExpressionTester.java index 5209aa8..2359be8 100644 --- a/test/sexpression/SExpressionTester.java +++ b/test/sexpression/SExpressionTester.java @@ -145,21 +145,13 @@ public class SExpressionTester { } @Test - public void invalidNumberException_HasCorrectSeverity() { - try { - new LispNumber("a"); - } catch (InvalidNumberException e) { - assertEquals(ERROR, e.getSeverity()); - } - } - - @Test - public void invalidNumberException_HasMessageText() { + public void invalidNumberException_HasCorrectAttributes() { try { new LispNumber("a"); } catch (InvalidNumberException e) { String message = e.getMessage(); + assertEquals(ERROR, e.getSeverity()); assertNotNull(message); assertTrue(message.length() > 0); }