Exception checking unit tests were refactored

This commit is contained in:
Mike Cifelli 2017-03-03 12:07:23 -05:00
parent 1f1586d53c
commit ba53448c9d
6 changed files with 20 additions and 60 deletions

View File

@ -169,16 +169,10 @@ public class ArgumentValidatorTester {
} }
@Test @Test
public void DottedArgumentListException_HasCorrectSeverity() { public void dottedArgumentListException_HasCorrectAttributes() {
DottedArgumentListException e = new DottedArgumentListException("TEST", NIL); DottedArgumentListException e = new DottedArgumentListException("TEST", NIL);
assertEquals(ERROR, e.getSeverity()); assertEquals(ERROR, e.getSeverity());
}
@Test
public void dottedArgumentListException_HasMessageText() {
DottedArgumentListException e = new DottedArgumentListException("TEST", NIL);
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 0); assertTrue(e.getMessage().length() > 0);
} }

View File

@ -1,5 +1,6 @@
package function.builtin; package function.builtin;
import static error.ErrorManager.Severity.ERROR;
import static function.builtin.EVAL.lookupSymbol; import static function.builtin.EVAL.lookupSymbol;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static sexpression.Nil.NIL; import static sexpression.Nil.NIL;
@ -81,17 +82,19 @@ public class EVALTester {
} }
@Test @Test
public void undefinedFunctionException_HasMessageText() { public void undefinedFunctionException_HasCorrectAttributes() {
UndefinedFunctionException e = new UndefinedFunctionException(NIL); UndefinedFunctionException e = new UndefinedFunctionException(NIL);
assertEquals(ERROR, e.getSeverity());
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 0); assertTrue(e.getMessage().length() > 0);
} }
@Test @Test
public void undefinedSymbolException_HasMessageText() { public void undefinedSymbolException_HasCorrectAttributes() {
UndefinedSymbolException e = new UndefinedSymbolException(NIL); UndefinedSymbolException e = new UndefinedSymbolException(NIL);
assertEquals(ERROR, e.getSeverity());
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 0); assertTrue(e.getMessage().length() > 0);
} }

View File

@ -1,5 +1,6 @@
package function.builtin; package function.builtin;
import static error.ErrorManager.Severity.ERROR;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static sexpression.Nil.NIL; import static sexpression.Nil.NIL;
import static testutil.TestUtilities.evaluateString; import static testutil.TestUtilities.evaluateString;
@ -68,9 +69,10 @@ public class SYMBOL_FUNCTIONTester {
} }
@Test @Test
public void undefinedSymbolFunctionException_HasMessageText() { public void undefinedSymbolFunctionException_HasCorrectAttributes() {
UndefinedSymbolFunctionException e = new UndefinedSymbolFunctionException(NIL); UndefinedSymbolFunctionException e = new UndefinedSymbolFunctionException(NIL);
assertEquals(ERROR, e.getSeverity());
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 0); assertTrue(e.getMessage().length() > 0);
} }

View File

@ -1,5 +1,6 @@
package interpreter; package interpreter;
import static error.ErrorManager.Severity.CRITICAL;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.*; import java.io.*;
@ -69,9 +70,10 @@ public class LispInterpreterBuilderTester {
} }
@Test @Test
public void interpreterAlreadyBuiltException_HasMessage() { public void interpreterAlreadyBuiltException_HasCorrectAttributes() {
InterpreterAlreadyBuiltException e = new InterpreterAlreadyBuiltException(); InterpreterAlreadyBuiltException e = new InterpreterAlreadyBuiltException();
assertEquals(CRITICAL, e.getSeverity());
assertNotNull(e.getMessage()); assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 0); assertTrue(e.getMessage().length() > 0);
} }

View File

@ -182,19 +182,7 @@ public class LispParserTester {
} }
@Test @Test
public void givenBadToken_ExceptionHasCorrectSeverity() { public void givenBadToken_ExceptionHasCorrectAttributes() {
String input = "[";
LispParser parser = createLispParser(input);
try {
parser.getNextSExpression();
} catch (BadCharacterException e) {
assertEquals(ERROR, e.getSeverity());
}
}
@Test
public void givenBadToken_ExceptionHasMessageText() {
String input = "["; String input = "[";
LispParser parser = createLispParser(input); LispParser parser = createLispParser(input);
@ -203,6 +191,7 @@ public class LispParserTester {
} catch (BadCharacterException e) { } catch (BadCharacterException e) {
String message = e.getMessage(); String message = e.getMessage();
assertEquals(ERROR, e.getSeverity());
assertNotNull(message); assertNotNull(message);
assertTrue(message.length() > 0); assertTrue(message.length() > 0);
} }
@ -225,19 +214,7 @@ public class LispParserTester {
} }
@Test @Test
public void givenUnterminatedList_ExceptionHasCorrectSeverity() { public void givenUnterminatedList_ExceptionHasCorrectAttributes() {
String input = "(bad list";
LispParser parser = createLispParser(input);
try {
parser.getNextSExpression();
} catch (EofEncounteredException e) {
assertEquals(ERROR, e.getSeverity());
}
}
@Test
public void givenUnterminatedList_ExceptionHasMessage() {
String input = "(bad list"; String input = "(bad list";
LispParser parser = createLispParser(input); LispParser parser = createLispParser(input);
@ -246,6 +223,7 @@ public class LispParserTester {
} catch (EofEncounteredException e) { } catch (EofEncounteredException e) {
String message = e.getMessage(); String message = e.getMessage();
assertEquals(ERROR, e.getSeverity());
assertNotNull(message); assertNotNull(message);
assertTrue(message.length() > 0); assertTrue(message.length() > 0);
} }
@ -260,19 +238,7 @@ public class LispParserTester {
} }
@Test @Test
public void givenUnmatchedRightParenthesis_ExceptionHasCorrectSeverity() { public void givenUnmatchedRightParenthesis_ExceptionHasCorrectAttributes() {
String input = ")";
LispParser parser = createLispParser(input);
try {
parser.getNextSExpression();
} catch (StartsWithRightParenthesisException e) {
assertEquals(ERROR, e.getSeverity());
}
}
@Test
public void givenUnmatchedRightParenthesis_ExceptionHasMessage() {
String input = ")"; String input = ")";
LispParser parser = createLispParser(input); LispParser parser = createLispParser(input);
@ -281,6 +247,7 @@ public class LispParserTester {
} catch (StartsWithRightParenthesisException e) { } catch (StartsWithRightParenthesisException e) {
String message = e.getMessage(); String message = e.getMessage();
assertEquals(ERROR, e.getSeverity());
assertNotNull(message); assertNotNull(message);
assertTrue(message.length() > 0); assertTrue(message.length() > 0);
} }

View File

@ -145,21 +145,13 @@ public class SExpressionTester {
} }
@Test @Test
public void invalidNumberException_HasCorrectSeverity() { public void invalidNumberException_HasCorrectAttributes() {
try {
new LispNumber("a");
} catch (InvalidNumberException e) {
assertEquals(ERROR, e.getSeverity());
}
}
@Test
public void invalidNumberException_HasMessageText() {
try { try {
new LispNumber("a"); new LispNumber("a");
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {
String message = e.getMessage(); String message = e.getMessage();
assertEquals(ERROR, e.getSeverity());
assertNotNull(message); assertNotNull(message);
assertTrue(message.length() > 0); assertTrue(message.length() > 0);
} }