Permalink
Browse files

WinBoard player is powered by possibility to set up a high-level list…

…ener to offer draw event from Winboard server
  • Loading branch information...
1 parent aa3e810 commit 50a3d88f4a7fe3ebad1dc7c6d4966737697fd8d8 @lrozenblyum committed Jan 1, 2013
@@ -1,5 +1,7 @@
package com.leokom.chess.framework;
+import com.leokom.chess.framework.DrawOfferedListener;
+
/**
* Engine-agnostic player.
* This interface is suggested to be common chess player abstraction
@@ -19,4 +21,6 @@
//TODO: think if it's player's property
void run();
+
+ void onDrawOffered( DrawOfferedListener listener );
}
@@ -36,6 +36,8 @@
this.communicator = communicator;
}
+
+
/**
* Switches Winboard engine in 'features set up mode'
*/
@@ -1,5 +1,6 @@
package com.leokom.chess.gui.winboard;
+import com.leokom.chess.framework.DrawOfferedListener;
import com.leokom.chess.framework.Player;
import com.leokom.chess.framework.PlayerMovedListener;
import org.apache.log4j.Logger;
@@ -104,6 +105,17 @@ public void run() {
}
}
+ @Override
+ public void onDrawOffered( final DrawOfferedListener listener ) {
+ //low-level interface adapting to the high-level
+ commander.onOfferDraw( new OfferDrawListener() {
+ @Override
+ public void execute() {
+ listener.anotherPlayerOfferedDraw();
+ }
+ } );
+ }
+
//listener to another player's move
@Override
public void anotherPlayerMoved( String move ) {
@@ -1,9 +1,11 @@
package com.leokom.chess.gui.winboard;
+import com.leokom.chess.framework.DrawOfferedListener;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
/**
* Check Winboard controller behaviour in combination with real
@@ -24,4 +26,23 @@ public void switchesWinboardToSetUpMode() {
verify( communicator ).send( "feature done=0" );
}
+
+
+ @Test
+ public void offerDrawListenerCalled() {
+ final WinboardCommunicator communicator = mock( WinboardCommunicator.class );
+
+ final WinboardCommander commander = new WinboardCommanderImpl( communicator );
+ final WinboardPlayer player = new WinboardPlayer( commander );
+
+ final DrawOfferedListener listenerToCall = mock( DrawOfferedListener.class );
+ player.onDrawOffered( listenerToCall );
+
+ //low-level
+ when( communicator.receive() ).thenReturn( "draw" );
+ //mid-level processing
+ commander.processInputFromServer();
+ //top-level component has set up the commander's listener correctly
+ verify( listenerToCall ).anotherPlayerOfferedDraw();
+ }
}
@@ -1,5 +1,6 @@
package com.leokom.chess.gui.winboard;
+import com.leokom.chess.framework.DrawOfferedListener;
import com.leokom.chess.framework.Player;
import com.leokom.chess.gui.Communicator;
import org.junit.Test;

0 comments on commit 50a3d88

Please sign in to comment.