Skip to content

Commit

Permalink
Removed usage of Mock Commander. Using Mockito feature to make generi…
Browse files Browse the repository at this point in the history
…c answer to a void method. However it looks a little bit more complex than the old approach
  • Loading branch information
lrozenblyum committed Dec 2, 2012
1 parent a429511 commit 4e6b06e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 79 deletions.
72 changes: 0 additions & 72 deletions src/test/java/com/leokom/chess/gui/winboard/MockCommander.java

This file was deleted.

Expand Up @@ -4,6 +4,8 @@
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -68,16 +70,21 @@ public void quitCommandSwitchesShutdownNeed() {
public void useCommanderForQuitCommandRealTest() {
//dummy implementation - each time anybody sets a protover listener -
//we quit IMMEDIATELY
WinboardCommander commander = new MockCommander() {
WinboardCommander commander = mock( WinboardCommander.class );

final ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
final WinboardPlayer winboardPlayer = new WinboardPlayer( commander );
verify( commander ).setQuitListener( quitListener.capture() );

doAnswer( new Answer() {
@Override
public void setQuitListener( final QuitListener quitListener ) {
quitListener.execute();
public Object answer( InvocationOnMock invocationOnMock ) {
quitListener.getValue().execute();
return null; //just for compiler... due to generic Answer interface
}
};
} ).when( commander ).processInputFromServer();

WinboardPlayer controller = new WinboardPlayer( commander );

controller.run();
winboardPlayer.run();
}

/**
Expand Down

0 comments on commit 4e6b06e

Please sign in to comment.