Skip to content
Browse files

Extracted method according to nice comment from Sasha Baglai

  • Loading branch information...
1 parent 1209491 commit 94b84beffc71e6307a4ef1e345a707bf313c92e2 @lrozenblyum committed Dec 16, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/test/java/com/leokom/chess/gui/winboard/WinBoardPlayerTest.java
View
17 src/test/java/com/leokom/chess/gui/winboard/WinBoardPlayerTest.java
@@ -7,6 +7,7 @@
import org.mockito.InOrder;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import org.mockito.stubbing.Stubber;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -91,19 +92,25 @@ public void useCommanderForQuitCommandRealTest() {
//we quit IMMEDIATELY
final WinboardCommander commander = mock( WinboardCommander.class );
- final ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
final Player winboardPlayer = new WinboardPlayer( commander );
+
+ executeQuitListener( commander ).when( commander ).processInputFromServer();
+
+ winboardPlayer.run();
+ }
+
+ private static Stubber executeQuitListener( WinboardCommander commander ) {
+ final ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
+
verify( commander ).setQuitListener( quitListener.capture() );
- doAnswer( new Answer() {
+ return doAnswer( new Answer() {
@Override
public Object answer( InvocationOnMock invocationOnMock ) {
quitListener.getValue().execute();
return null; //just for compiler... due to generic Answer interface
}
- } ).when( commander ).processInputFromServer();
-
- winboardPlayer.run();
+ } );
}
/**

0 comments on commit 94b84be

Please sign in to comment.
Something went wrong with that request. Please try again.