Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed usage of Mock Commander. Using Mockito feature to make generi…

…c answer to a void method. However it looks a little bit more complex than the old approach
  • Loading branch information...
commit 4e6b06eb1ccebf07f8d871ab5913f6e2ec28f0fc 1 parent a429511
@lrozenblyum authored
View
72 src/test/java/com/leokom/chess/gui/winboard/MockCommander.java
@@ -1,72 +0,0 @@
-package com.leokom.chess.gui.winboard;
-
-/**
- * Author: Leonid
- * Date-time: 10.11.12 21:56
- */
-public class MockCommander implements WinboardCommander {
- @Override
- public void startInit() {
- }
-
- @Override
- public void enableUserMovePrefixes() {
- }
-
- @Override
- public void finishInit() {
- }
-
- @Override
- public void agreeToDrawOffer() {
- }
-
- @Override
- public void setProtoverListener( ProtoverListener protoverListener ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void setQuitListener( QuitListener listener ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void processInputFromServer() {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void setGoListener( GoListener listener ) {
- }
-
- @Override
- public void setUserMoveListener( UserMoveListener listener ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void setOfferDrawListener( OfferDrawListener listener ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void setXboardListener( XBoardListener listener ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void anotherPlayerMoved( String move ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void offerDraw() {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- @Override
- public void resign() {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-}
View
21 src/test/java/com/leokom/chess/gui/winboard/WinBoardPlayerTest.java
@@ -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;
@@ -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();
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.