package token; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import file.FilePosition; import token.Token.Type; import token.TokenFactory.BadCharacterException; public class TokenFactoryTester { private TokenFactory tokenFactory; private FilePosition testPosition; @Before public void setUp() throws Exception { tokenFactory = new TokenFactoryImpl(); testPosition = new FilePosition("testFile"); testPosition.setLineNumber(0); testPosition.setColumnNumber(0); } private Type getCreatedTokenType(String text) { return tokenFactory.createToken(text, testPosition).getType(); } @Test public void testEOFTokenCreation() { assertEquals(Type.EOF, tokenFactory.createEOFToken(testPosition).getType()); } @Test(expected = RuntimeException.class) public void testEmptyString_ThrowsException() { String text = ""; tokenFactory.createToken(text, testPosition); } @Test public void testLeftParenthesisCreation() { String text = "("; assertEquals(Type.LEFT_PAREN, getCreatedTokenType(text)); } @Test public void testRightParenthesisCreation() { String text = ")"; assertEquals(Type.RIGHT_PAREN, getCreatedTokenType(text)); } @Test public void testQuoteMarkCreation() { String text = "'"; assertEquals(Type.QUOTE_MARK, getCreatedTokenType(text)); } @Test public void testNumberCreation() { String text = "987"; assertEquals(Type.NUMBER, getCreatedTokenType(text)); } @Test public void testIdentifierCreation() { String text = "identifier"; assertEquals(Type.IDENTIFIER, getCreatedTokenType(text)); } @Test public void testStringCreation() { String text = "\"string\""; assertEquals(Type.STRING, getCreatedTokenType(text)); } @Test(expected = BadCharacterException.class) public void testBadCharacter() { String text = "[abc]"; tokenFactory.createToken(text, testPosition); } }