Last active
August 29, 2015 13:55
-
-
Save fourcube/8692248 to your computer and use it in GitHub Desktop.
Revisions
-
fourcube revised this gist
Jan 29, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,8 +20,7 @@ public class InterpreterImplTest { InterpreterImpl cut; @Mock Command c; @Rule ExpectedException exception = ExpectedException.none(); @Before public void setUp() { -
fourcube revised this gist
Jan 29, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,11 +77,13 @@ public void interactiveScriptShouldTerminateOnEOF() { cut.execute(new StringReader(statement), true); } @Test public void nonInteractiveScriptShouldTerminateOnEOF() { String invalidStatement = "EXEC foo bar <EOF>"; cut.execute(new StringReader(invalidStatement), false); } @Test public void shouldNotCallExecuteWhenMatchesReturnsFalse() { String invalidStatement = "EXEC null;"; when(c.matches(Arrays.asList("null"))).thenReturn(false); @@ -92,6 +94,7 @@ public void shouldNotCallExecuteWhenMatchesReturnsFalse() { verifyNoMoreInteractions(c); } @Test public void shouldCallExecuteWhenMatchesReturnsTrue() { String validStatement = "EXEC foo bar;"; when(c.matches(Arrays.asList("foo", "bar"))).thenReturn(true); @@ -100,7 +103,6 @@ public void shouldCallExecuteWhenMatchesReturnsTrue() { verify(c,times(1)).matches(Arrays.asList("foo", "bar")); verify(c,times(1)).execute(Arrays.asList("foo", "bar")); } // Example usage: -
fourcube renamed this gist
Jan 29, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fourcube created this gist
Jan 29, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,116 @@ package svv; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import static org.mockito.Mockito.*; import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.internal.matchers.VarargMatcher; import org.mockito.runners.MockitoJUnitRunner; import java.io.StringReader; import java.util.Arrays; @RunWith(MockitoJUnitRunner.class) public class InterpreterImplTest { InterpreterImpl cut; @Mock Command c; @Rule ExpectedException exception = ExpectedException.none(); @Before public void setUp() { cut = new InterpreterImpl(); cut.registerCommand("EXEC", c); } @Test public void shouldAcceptInteractiveTokenSequence() { String interactiveValidStatement = "EXEC foo bA0123456789_-r \";.$§%\"<EOF>"; cut.execute(new StringReader(interactiveValidStatement), true); verify(c, times(1)).matches(Arrays.asList("foo", "bA0123456789_-r", ";.$§%")); verify(c, times(1)).execute(Arrays.asList("foo", "bA0123456789_-r", ";.$§%")); } @Test public void shouldAcceptNonInteractiveSequenceTerminator() { String nonInteractiveValidStatement = "EXEC foo bA0123456789_-r \";.$§%\";"; cut.execute(new StringReader(nonInteractiveValidStatement), false); verify(c, times(1)).matches(Arrays.asList("foo", "bA0123456789_-r")); verify(c, times(1)).execute(Arrays.asList("foo", "bA0123456789_-r")); } @Test public void shouldNotAcceptNonEscapedSpecialCharacters() { String invalidStatement = "EXEC foo \n$%.;"; exception.expect(SyntaxException.class); try { cut.execute(new StringReader(invalidStatement), false); } finally { verifyZeroInteractions(c); } } @Test public void shouldNotAcceptArgumentWithoutClosingQuotationMarks() { String invalidStatement = "EXEC foo \"$ ;"; exception.expect(SyntaxException.class); try { cut.execute(new StringReader(invalidStatement), false); } finally { verifyZeroInteractions(c); } } @Test public void interactiveScriptShouldTerminateOnEOF() { String statement = "EXEC foo bar <EOF>"; cut.execute(new StringReader(statement), true); } public void nonInteractiveScriptShouldTerminateOnEOF() { String invalidStatement = "EXEC foo bar <EOF>"; cut.execute(new StringReader(invalidStatement), false); } public void shouldNotCallExecuteWhenMatchesReturnsFalse() { String invalidStatement = "EXEC null;"; when(c.matches(Arrays.asList("null"))).thenReturn(false); cut.execute(new StringReader(invalidStatement), false); verify(c,times(1)).matches(Arrays.asList("null")); verifyNoMoreInteractions(c); } public void shouldCallExecuteWhenMatchesReturnsTrue() { String validStatement = "EXEC foo bar;"; when(c.matches(Arrays.asList("foo", "bar"))).thenReturn(true); cut.execute(new StringReader(validStatement), false); verify(c,times(1)).matches(Arrays.asList("foo", "bar")); verify(c,times(1)).execute(Arrays.asList("foo", "bar")); verifyNoMoreInteractions(c); } // Example usage: // when(c).execute(argThat(new DerpMatcher<List<String>>())); public class DerpMatcher<T> extends ArgumentMatcher<T> implements VarargMatcher { @Override public boolean matches(Object argument) { return false; } } }