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
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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}