132 lines
4.0 KiB
Java
132 lines
4.0 KiB
Java
|
package eval.argument;
|
||
|
|
||
|
import static org.junit.Assert.*;
|
||
|
|
||
|
import org.junit.*;
|
||
|
|
||
|
import error.ErrorManager;
|
||
|
import eval.argument.ArgumentValidator.*;
|
||
|
import sexpression.*;
|
||
|
|
||
|
public class ArgumentValidatorTester {
|
||
|
|
||
|
private ArgumentValidator validator;
|
||
|
|
||
|
private Cons makeArgumentListOfSize(int size) {
|
||
|
Cons argumentList = Nil.getUniqueInstance();
|
||
|
|
||
|
for (int i = 0; i < size; i++)
|
||
|
argumentList = new Cons(Nil.getUniqueInstance(), argumentList);
|
||
|
|
||
|
return argumentList;
|
||
|
}
|
||
|
|
||
|
@Before
|
||
|
public void setUp() throws Exception {
|
||
|
validator = new ArgumentValidator("TEST");
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void noConstraints_DoesNotThrowExceptionWithNoArguments() {
|
||
|
validator.validate(makeArgumentListOfSize(0));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void noConstraints_DoesNotThrowExceptionWithOneArgument() {
|
||
|
validator.validate(makeArgumentListOfSize(1));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void noConstraints_DoesNotThrowExceptionWithManyArguments() {
|
||
|
validator.validate(makeArgumentListOfSize(20));
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooFewArgumentsException.class)
|
||
|
public void tooFewArgumentsWithMinimumSet_ThrowsException() {
|
||
|
validator.setMinimumNumberOfArguments(1);
|
||
|
validator.validate(makeArgumentListOfSize(0));
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooManyArgumentsException.class)
|
||
|
public void tooManyArgumentsWithMaximumSet_ThrowsException() {
|
||
|
validator.setMaximumNumberOfArguments(1);
|
||
|
validator.validate(makeArgumentListOfSize(2));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void exactNumberOfArguments_DoesNotThrowException() {
|
||
|
validator.setExactNumberOfArguments(5);
|
||
|
validator.validate(makeArgumentListOfSize(5));
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooFewArgumentsException.class)
|
||
|
public void tooFewArgumentsWithExactSet_ThrowsException() {
|
||
|
validator.setExactNumberOfArguments(3);
|
||
|
validator.validate(makeArgumentListOfSize(2));
|
||
|
}
|
||
|
|
||
|
@Test(expected = TooManyArgumentsException.class)
|
||
|
public void tooManyArgumentsWithExactSet_ThrowsException() {
|
||
|
validator.setExactNumberOfArguments(3);
|
||
|
validator.validate(makeArgumentListOfSize(4));
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void tooManyArgumentsException_HasCorrectSeverity() {
|
||
|
TooManyArgumentsException e = new TooManyArgumentsException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void tooManyArgumentsException_HasMessageText() {
|
||
|
TooManyArgumentsException e = new TooManyArgumentsException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertNotNull(e.getMessage());
|
||
|
assertTrue(e.getMessage().length() > 0);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void tooFewArgumentsException_HasCorrectSeverity() {
|
||
|
TooFewArgumentsException e = new TooFewArgumentsException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void tooFewArgumentsException_HasMessageText() {
|
||
|
TooFewArgumentsException e = new TooFewArgumentsException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertNotNull(e.getMessage());
|
||
|
assertTrue(e.getMessage().length() > 0);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void BadArgumentTypeException_HasCorrectSeverity() {
|
||
|
BadArgumentTypeException e = new BadArgumentTypeException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertTrue(e.getSeverity() < ErrorManager.CRITICAL_LEVEL);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void BadArgumentTypeException_HasMessageText() {
|
||
|
BadArgumentTypeException e = new BadArgumentTypeException("TEST", Nil.getUniqueInstance());
|
||
|
|
||
|
assertNotNull(e.getMessage());
|
||
|
assertTrue(e.getMessage().length() > 0);
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void correctArgumentType_DoesNotThrowException() {
|
||
|
validator.setArgumentType(Nil.class);
|
||
|
validator.validate(makeArgumentListOfSize(1));
|
||
|
}
|
||
|
|
||
|
@Test(expected = BadArgumentTypeException.class)
|
||
|
public void badArgumentType_ThrowsException() {
|
||
|
validator.setArgumentType(LispString.class);
|
||
|
validator.validate(makeArgumentListOfSize(1));
|
||
|
}
|
||
|
|
||
|
}
|