Refactor unit tests

This commit is contained in:
Mike Cifelli 2017-11-23 11:35:28 -05:00
parent f3923cadc0
commit c4e6de88e1
8 changed files with 161 additions and 155 deletions

View File

@ -1,8 +1,8 @@
package terminal; package terminal;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertFalse; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertThat;
import static terminal.ControlSequenceHandler.isEscape; import static terminal.ControlSequenceHandler.isEscape;
import static terminal.SelectGraphicRendition.GREEN; import static terminal.SelectGraphicRendition.GREEN;
import static terminal.SelectGraphicRendition.PURPLE; import static terminal.SelectGraphicRendition.PURPLE;
@ -42,95 +42,95 @@ public class ControlSequenceHandlerTest {
@Test @Test
public void isEscapeDetectsNonEscapeCharacter() { public void isEscapeDetectsNonEscapeCharacter() {
assertFalse(isEscape('x')); assertThat(isEscape('x'), is(false));
} }
@Test @Test
public void isEscapeDetectsEscapeCharacter() { public void isEscapeDetectsEscapeCharacter() {
assertTrue(isEscape('\u001b')); assertThat(isEscape('\u001b'), is(true));
} }
@Test @Test
public void correctlyParsesControlSequence_LeavesRestOfStreamIntact() { public void correctlyParsesControlSequence_LeavesRestOfStreamIntact() {
SafeInputStream input = createSafeInputStream("[32mdata"); SafeInputStream input = createSafeInputStream("[32mdata");
handler.parse(input); handler.parse(input);
assertEquals("data", readRemaining(input)); assertThat(readRemaining(input), is("data"));
} }
@Test @Test
public void unterminatedControlSequence_OnlyConsumesFirstNonSequenceCharacter() { public void unterminatedControlSequence_OnlyConsumesFirstNonSequenceCharacter() {
SafeInputStream input = createSafeInputStream("[32data"); SafeInputStream input = createSafeInputStream("[32data");
handler.parse(input); handler.parse(input);
assertEquals("ata", readRemaining(input)); assertThat(readRemaining(input), is("ata"));
} }
@Test @Test
public void malformedControlSequence_OnlyConsumesOneCharacter() { public void malformedControlSequence_OnlyConsumesOneCharacter() {
SafeInputStream input = createSafeInputStream("32mdata"); SafeInputStream input = createSafeInputStream("32mdata");
handler.parse(input); handler.parse(input);
assertEquals("2mdata", readRemaining(input)); assertThat(readRemaining(input), is("2mdata"));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_EOF() { public void parsedControlSequenceIsCorrectType_EOF() {
SafeInputStream input = createSafeInputStream(""); SafeInputStream input = createSafeInputStream("");
assertTrue(handler.parse(input) instanceof NullControlSequence); assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_EOF_AfterFirstCharacter() { public void parsedControlSequenceIsCorrectType_EOF_AfterFirstCharacter() {
SafeInputStream input = createSafeInputStream("["); SafeInputStream input = createSafeInputStream("[");
assertTrue(handler.parse(input) instanceof NullControlSequence); assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_UnterminatedControlSequence() { public void parsedControlSequenceIsCorrectType_UnterminatedControlSequence() {
SafeInputStream input = createSafeInputStream("[data"); SafeInputStream input = createSafeInputStream("[data");
assertTrue(handler.parse(input) instanceof NullControlSequence); assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_MalformedControlSequence() { public void parsedControlSequenceIsCorrectType_MalformedControlSequence() {
SafeInputStream input = createSafeInputStream("32mdata"); SafeInputStream input = createSafeInputStream("32mdata");
assertTrue(handler.parse(input) instanceof NullControlSequence); assertThat(handler.parse(input), instanceOf(NullControlSequence.class));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_SGR_Reset() { public void parsedControlSequenceIsCorrectType_SGR_Reset() {
SafeInputStream input = createSafeInputStream("[0m"); SafeInputStream input = createSafeInputStream("[0m");
assertEquals(RESET, handler.parse(input)); assertThat(handler.parse(input), is(RESET));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_SGR_Red() { public void parsedControlSequenceIsCorrectType_SGR_Red() {
SafeInputStream input = createSafeInputStream("[31m"); SafeInputStream input = createSafeInputStream("[31m");
assertEquals(RED, handler.parse(input)); assertThat(handler.parse(input), is(RED));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_SGR_Green() { public void parsedControlSequenceIsCorrectType_SGR_Green() {
SafeInputStream input = createSafeInputStream("[32m"); SafeInputStream input = createSafeInputStream("[32m");
assertEquals(GREEN, handler.parse(input)); assertThat(handler.parse(input), is(GREEN));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_SGR_Yellow() { public void parsedControlSequenceIsCorrectType_SGR_Yellow() {
SafeInputStream input = createSafeInputStream("[33m"); SafeInputStream input = createSafeInputStream("[33m");
assertEquals(YELLOW, handler.parse(input)); assertThat(handler.parse(input), is(YELLOW));
} }
@Test @Test
public void parsedControlSequenceIsCorrectType_SGR_Purple() { public void parsedControlSequenceIsCorrectType_SGR_Purple() {
SafeInputStream input = createSafeInputStream("[35m"); SafeInputStream input = createSafeInputStream("[35m");
assertEquals(PURPLE, handler.parse(input)); assertThat(handler.parse(input), is(PURPLE));
} }
@Test @Test
public void parseMultipleControlSequences() { public void parseMultipleControlSequences() {
SafeInputStream input = createSafeInputStream("[35m[32m[0m"); SafeInputStream input = createSafeInputStream("[35m[32m[0m");
assertEquals(PURPLE, handler.parse(input)); assertThat(handler.parse(input), is(PURPLE));
assertEquals(GREEN, handler.parse(input)); assertThat(handler.parse(input), is(GREEN));
assertEquals(RESET, handler.parse(input)); assertThat(handler.parse(input), is(RESET));
} }
} }

View File

@ -1,7 +1,9 @@
package terminal; package terminal;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertTrue; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.isEmptyString;
import static org.junit.Assert.assertThat;
import static terminal.SelectGraphicRendition.GREEN; import static terminal.SelectGraphicRendition.GREEN;
import static terminal.SelectGraphicRendition.PURPLE; import static terminal.SelectGraphicRendition.PURPLE;
import static terminal.SelectGraphicRendition.RED; import static terminal.SelectGraphicRendition.RED;
@ -49,48 +51,48 @@ public class ControlSequenceTest {
ControlSequence nullControlSequence = new NullControlSequence(); ControlSequence nullControlSequence = new NullControlSequence();
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
nullControlSequence.applyTo(terminal); nullControlSequence.applyTo(terminal);
assertTrue(indicatorSet.isEmpty()); assertThat(indicatorSet, empty());
} }
@Test @Test
public void controlSequenceUpdatesTerminal_SGR_Reset() { public void controlSequenceUpdatesTerminal_SGR_Reset() {
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
RESET.applyTo(terminal); RESET.applyTo(terminal);
assertTrue(indicatorSet.contains("RESET")); assertThat(indicatorSet, contains("RESET"));
} }
@Test @Test
public void controlSequenceUpdatesTerminal_SGR_Red() { public void controlSequenceUpdatesTerminal_SGR_Red() {
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
RED.applyTo(terminal); RED.applyTo(terminal);
assertTrue(indicatorSet.contains("RED")); assertThat(indicatorSet, contains("RED"));
} }
@Test @Test
public void controlSequenceUpdatesTerminal_SGR_Green() { public void controlSequenceUpdatesTerminal_SGR_Green() {
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
GREEN.applyTo(terminal); GREEN.applyTo(terminal);
assertTrue(indicatorSet.contains("GREEN")); assertThat(indicatorSet, contains("GREEN"));
} }
@Test @Test
public void controlSequenceUpdatesTerminal_SGR_Yellow() { public void controlSequenceUpdatesTerminal_SGR_Yellow() {
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
YELLOW.applyTo(terminal); YELLOW.applyTo(terminal);
assertTrue(indicatorSet.contains("YELLOW")); assertThat(indicatorSet, contains("YELLOW"));
} }
@Test @Test
public void controlSequenceUpdatesTerminal_SGR_Purple() { public void controlSequenceUpdatesTerminal_SGR_Purple() {
VirtualTerminal terminal = createTerminalWithIndicators(); VirtualTerminal terminal = createTerminalWithIndicators();
PURPLE.applyTo(terminal); PURPLE.applyTo(terminal);
assertTrue(indicatorSet.contains("MAGENTA")); assertThat(indicatorSet, contains("MAGENTA"));
} }
@Test @Test
public void nullControlSequenceHasCorrectCode() { public void nullControlSequenceHasCorrectCode() {
ControlSequence nullControlSequence = new NullControlSequence(); ControlSequence nullControlSequence = new NullControlSequence();
assertEquals("", nullControlSequence.getCode()); assertThat(nullControlSequence.getCode(), isEmptyString());
} }
@Test @Test

View File

@ -1,7 +1,7 @@
package terminal; package terminal;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertThat;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -12,19 +12,19 @@ public class TerminalHistoryTest {
private TerminalHistory history; private TerminalHistory history;
private void assertAtBeginning() { private void assertAtBeginning() {
assertTrue(history.isBeginning()); assertThat(history.isBeginning(), is(true));
} }
private void assertAtEnd() { private void assertAtEnd() {
assertTrue(history.isEnd()); assertThat(history.isEnd(), is(true));
} }
private void assertPrevious(String expected) { private void assertPrevious(String expected) {
assertEquals(expected, history.getPreviousLine()); assertThat(history.getPreviousLine(), is(expected));
} }
private void assertNext(String expected) { private void assertNext(String expected) {
assertEquals(expected, history.getNextLine()); assertThat(history.getNextLine(), is(expected));
} }
@Before @Before

View File

@ -1,6 +1,7 @@
package terminal; package terminal;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static terminal.LispTerminal.END_OF_SEGMENT; import static terminal.LispTerminal.END_OF_SEGMENT;
@ -136,8 +137,8 @@ public class VirtualTerminalInteractor {
} }
public void assertCursorPosition(int column, int row) { public void assertCursorPosition(int column, int row) {
assertEquals(column, virtualTerminal.getCursorPosition().getColumn()); assertThat(virtualTerminal.getCursorPosition().getColumn(), is(column));
assertEquals(row, virtualTerminal.getCursorPosition().getRow()); assertThat(virtualTerminal.getCursorPosition().getRow(), is(row));
} }
public void assertScreenText(String... rows) { public void assertScreenText(String... rows) {
@ -150,7 +151,7 @@ public class VirtualTerminalInteractor {
TerminalPosition position = new TerminalPosition(column, row); TerminalPosition position = new TerminalPosition(column, row);
String expected = String.valueOf(character); String expected = String.valueOf(character);
String actual = String.valueOf(virtualTerminal.getCharacter(position).getCharacter()); String actual = String.valueOf(virtualTerminal.getCharacter(position).getCharacter());
assertEquals(expected, actual); assertThat(actual, is(expected));
} }
public void assertInputWritten(String expected) { public void assertInputWritten(String expected) {
@ -163,7 +164,7 @@ public class VirtualTerminalInteractor {
actual += (char) c; actual += (char) c;
} catch (IOException ignored) {} } catch (IOException ignored) {}
assertEquals(expected, actual); assertThat(actual, is(expected));
} }
public void assertInputStreamClosed() { public void assertInputStreamClosed() {

View File

@ -1,8 +1,7 @@
package testutil; package testutil;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static sexpression.Nil.NIL; import static sexpression.Nil.NIL;
import static sexpression.Symbol.T; import static sexpression.Symbol.T;
@ -11,121 +10,121 @@ import sexpression.SExpression;
public final class TypeAssertions { public final class TypeAssertions {
public static void assertList(SExpression sExpression) { public static void assertList(SExpression sExpression) {
assertFalse(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(false));
assertTrue(sExpression.isCons()); assertThat(sExpression.isCons(), is(true));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertTrue(sExpression.isList()); assertThat(sExpression.isList(), is(true));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertNil(SExpression sExpression) { public static void assertNil(SExpression sExpression) {
assertEquals(NIL, sExpression); assertThat(sExpression, is(NIL));
assertTrue(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(true));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertTrue(sExpression.isList()); assertThat(sExpression.isList(), is(true));
assertTrue(sExpression.isNull()); assertThat(sExpression.isNull(), is(true));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertTrue(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(true));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertNumber(SExpression sExpression) { public static void assertNumber(SExpression sExpression) {
assertTrue(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(true));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertTrue(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(true));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertString(SExpression sExpression) { public static void assertString(SExpression sExpression) {
assertTrue(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(true));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertTrue(sExpression.isString()); assertThat(sExpression.isString(), is(true));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertSymbol(SExpression sExpression) { public static void assertSymbol(SExpression sExpression) {
assertTrue(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(true));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertTrue(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(true));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertT(SExpression sExpression) { public static void assertT(SExpression sExpression) {
assertEquals(T, sExpression); assertThat(sExpression, is(T));
} }
public static void assertBackTickExpression(SExpression sExpression) { public static void assertBackTickExpression(SExpression sExpression) {
assertFalse(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(false));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertTrue(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(true));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertCommaExpression(SExpression sExpression) { public static void assertCommaExpression(SExpression sExpression) {
assertFalse(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(false));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertTrue(sExpression.isComma()); assertThat(sExpression.isComma(), is(true));
assertFalse(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(false));
} }
public static void assertAtSignExpression(SExpression sExpression) { public static void assertAtSignExpression(SExpression sExpression) {
assertFalse(sExpression.isAtom()); assertThat(sExpression.isAtom(), is(false));
assertFalse(sExpression.isCons()); assertThat(sExpression.isCons(), is(false));
assertFalse(sExpression.isFunction()); assertThat(sExpression.isFunction(), is(false));
assertFalse(sExpression.isList()); assertThat(sExpression.isList(), is(false));
assertFalse(sExpression.isNull()); assertThat(sExpression.isNull(), is(false));
assertFalse(sExpression.isNumber()); assertThat(sExpression.isNumber(), is(false));
assertFalse(sExpression.isString()); assertThat(sExpression.isString(), is(false));
assertFalse(sExpression.isSymbol()); assertThat(sExpression.isSymbol(), is(false));
assertFalse(sExpression.isBackquote()); assertThat(sExpression.isBackquote(), is(false));
assertFalse(sExpression.isComma()); assertThat(sExpression.isComma(), is(false));
assertTrue(sExpression.isAtSign()); assertThat(sExpression.isAtSign(), is(true));
} }
} }

View File

@ -1,9 +1,11 @@
package token; package token;
import static error.ErrorManager.Severity.CRITICAL; import static error.ErrorManager.Severity.CRITICAL;
import static org.junit.Assert.assertEquals; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertNotNull; import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertTrue; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -31,55 +33,55 @@ public class TokenFactoryTest {
@Test @Test
public void eofTokenCreation() { public void eofTokenCreation() {
assertTrue(tokenFactory.createEofToken(testPosition) instanceof Eof); assertThat(tokenFactory.createEofToken(testPosition), instanceOf(Eof.class));
} }
@Test @Test
public void leftParenthesisCreation() { public void leftParenthesisCreation() {
String text = "("; String text = "(";
assertTrue(createToken(text) instanceof LeftParenthesis); assertThat(createToken(text), instanceOf(LeftParenthesis.class));
} }
@Test @Test
public void rightParenthesisCreation() { public void rightParenthesisCreation() {
String text = ")"; String text = ")";
assertTrue(createToken(text) instanceof RightParenthesis); assertThat(createToken(text), instanceOf(RightParenthesis.class));
} }
@Test @Test
public void quoteMarkCreation() { public void quoteMarkCreation() {
String text = "'"; String text = "'";
assertTrue(createToken(text) instanceof QuoteMark); assertThat(createToken(text), instanceOf(QuoteMark.class));
} }
@Test @Test
public void numberCreation() { public void numberCreation() {
String text = "987"; String text = "987";
assertTrue(createToken(text) instanceof Number); assertThat(createToken(text), instanceOf(Number.class));
} }
@Test @Test
public void prefixedNumberCreation() { public void prefixedNumberCreation() {
String text = "-987"; String text = "-987";
assertTrue(createToken(text) instanceof Number); assertThat(createToken(text), instanceOf(Number.class));
} }
@Test @Test
public void identifierCreation() { public void identifierCreation() {
String text = "identifier"; String text = "identifier";
assertTrue(createToken(text) instanceof Identifier); assertThat(createToken(text), instanceOf(Identifier.class));
} }
@Test @Test
public void prefixedIdentifierCreation() { public void prefixedIdentifierCreation() {
String text = "-identifier"; String text = "-identifier";
assertTrue(createToken(text) instanceof Identifier); assertThat(createToken(text), instanceOf(Identifier.class));
} }
@Test @Test
public void stringCreation() { public void stringCreation() {
String text = "\"string\""; String text = "\"string\"";
assertTrue(createToken(text) instanceof QuotedString); assertThat(createToken(text), instanceOf(QuotedString.class));
} }
@Test(expected = EmptyTokenTextException.class) @Test(expected = EmptyTokenTextException.class)
@ -93,9 +95,9 @@ public class TokenFactoryTest {
createToken(""); createToken("");
} catch (EmptyTokenTextException e) { } catch (EmptyTokenTextException e) {
String message = e.getMessage(); String message = e.getMessage();
assertNotNull(message); assertThat(message, is(notNullValue()));
assertTrue(message.length() > 0); assertThat(message.length(), greaterThan(0));
assertEquals(CRITICAL, e.getSeverity()); assertThat(e.getSeverity(), is(CRITICAL));
} }
} }
@ -107,19 +109,19 @@ public class TokenFactoryTest {
@Test @Test
public void backTickCreation() { public void backTickCreation() {
String text = "`"; String text = "`";
assertTrue(createToken(text) instanceof Backquote); assertThat(createToken(text), instanceOf(Backquote.class));
} }
@Test @Test
public void commaCreation() { public void commaCreation() {
String text = ","; String text = ",";
assertTrue(createToken(text) instanceof Comma); assertThat(createToken(text), instanceOf(Comma.class));
} }
@Test @Test
public void atSignCreation() { public void atSignCreation() {
String text = "@"; String text = "@";
assertTrue(createToken(text) instanceof AtSign); assertThat(createToken(text), instanceOf(AtSign.class));
} }
} }

View File

@ -1,6 +1,7 @@
package util; package util;
import static org.junit.Assert.assertTrue; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -13,7 +14,7 @@ public class CharactersTest {
public void constructorIsPrivate() throws Exception { public void constructorIsPrivate() throws Exception {
Constructor<Characters> constructor = Characters.class.getDeclaredConstructor(); Constructor<Characters> constructor = Characters.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers())); assertThat(Modifier.isPrivate(constructor.getModifiers()), is(true));
constructor.setAccessible(true); constructor.setAccessible(true);
constructor.newInstance(); constructor.newInstance();
} }

View File

@ -1,6 +1,7 @@
package util; package util;
import static org.junit.Assert.assertTrue; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -13,7 +14,7 @@ public class PathTest {
public void constructorIsPrivate() throws Exception { public void constructorIsPrivate() throws Exception {
Constructor<Path> constructor = Path.class.getDeclaredConstructor(); Constructor<Path> constructor = Path.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers())); assertThat(Modifier.isPrivate(constructor.getModifiers()), is(true));
constructor.setAccessible(true); constructor.setAccessible(true);
constructor.newInstance(); constructor.newInstance();
} }