Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Commander's setters for listeners renamed to 'on' convention

  • Loading branch information...
commit ef0fac7fb418001605e1d90ce45ca866c0a05fba 1 parent 94b84be
@lrozenblyum authored
View
28 src/main/java/com/leokom/chess/gui/winboard/WinboardCommander.java
@@ -1,8 +1,8 @@
package com.leokom.chess.gui.winboard;
/**
- * Low-level Winboard-commands for some abstraction
- * and easier testing.
+ * Low-level Winboard-commands for some abstraction and easier testing.
+ * The 'on' methods set up listeners to some events received from Winboard server
* Author: Leonid
* Date-time: 10.11.12 21:54
*/
@@ -20,28 +20,26 @@
void agreeToDrawOffer();
- void setProtoverListener( ProtoverListener protoverListener );
- void setQuitListener( QuitListener listener );
-
/**
* Fetch input from the underlying communication component
- * Call some listeners if any....
+ * Dispatch listeners (call them depending on the input)
*/
void processInputFromServer();
- void setGoListener( GoListener listener );
-
- void setUserMoveListener( UserMoveListener listener );
-
- void setOfferDrawListener( OfferDrawListener listener );
-
- //TODO: add analyze if this line is received immediately after xboard
+ //TODO: add analyze if this command is received immediately after xboard
//if not - we may assume it's protocol v1
- void setXboardListener( XBoardListener listener );
+ void onXBoard( XBoardListener listener );
void anotherPlayerMoved( String move );
void offerDraw();
void resign();
-}
+
+
+ void onProtover( ProtoverListener protoverListener );
+ void onQuit( QuitListener listener );
+ void onGo( GoListener listener );
+ void onUserMove( UserMoveListener listener );
+ void onOfferDraw( OfferDrawListener listener );
+}
View
39 src/main/java/com/leokom/chess/gui/winboard/WinboardCommanderImpl.java
@@ -29,7 +29,7 @@
*
* @param communicator low-level framework to use to send/receive the commands
*/
- public WinboardCommanderImpl( Communicator communicator ) {
+ WinboardCommanderImpl( Communicator communicator ) {
this.communicator = communicator;
}
@@ -62,48 +62,49 @@ public void agreeToDrawOffer() {
}
@Override
- public void setProtoverListener( ProtoverListener protoverListener ) {
- this.protoverListener = protoverListener;
+ public void anotherPlayerMoved( String move ) {
+ this.communicator.send( "move " + move );
}
@Override
- public void setQuitListener( QuitListener listener ) {
- this.quitListener = listener;
+ public void offerDraw() {
+ this.communicator.send( "offer draw" );
}
@Override
- public void setGoListener( GoListener listener ) {
- this.goListener = listener;
+ public void resign() {
+ this.communicator.send( "resign" );
}
+
@Override
- public void setUserMoveListener( UserMoveListener listener ) {
- this.userMoveListener = listener;
+ public void onProtover( ProtoverListener protoverListener ) {
+ this.protoverListener = protoverListener;
}
@Override
- public void setOfferDrawListener( OfferDrawListener listener ) {
- this.offerDrawListener = listener;
+ public void onQuit( QuitListener listener ) {
+ this.quitListener = listener;
}
@Override
- public void setXboardListener( XBoardListener listener ) {
- this.xboardListener = listener;
+ public void onGo( GoListener listener ) {
+ this.goListener = listener;
}
@Override
- public void anotherPlayerMoved( String move ) {
- this.communicator.send( "move " + move );
+ public void onUserMove( UserMoveListener listener ) {
+ this.userMoveListener = listener;
}
@Override
- public void offerDraw() {
- this.communicator.send( "offer draw" );
+ public void onOfferDraw( OfferDrawListener listener ) {
+ this.offerDrawListener = listener;
}
@Override
- public void resign() {
- this.communicator.send( "resign" );
+ public void onXBoard( XBoardListener listener ) {
+ this.xboardListener = listener;
}
@Override
View
30 src/main/java/com/leokom/chess/gui/winboard/WinboardPlayer.java
@@ -30,45 +30,45 @@
- commander.setXboardListener( new XBoardListener() {
+ commander.onXBoard( new XBoardListener() {
@Override
public void execute() {
logger.info( "Ready to work" );
}
- });
+ } );
//TODO: it's caller's responsibility! Remove this logic!
- commander.setOfferDrawListener(
- new OfferDrawListener() {
- @Override
- public void execute() {
- commander.agreeToDrawOffer();
+ commander.onOfferDraw(
+ new OfferDrawListener() {
+ @Override
+ public void execute() {
+ commander.agreeToDrawOffer();
+ }
}
- }
);
- commander.setQuitListener( new QuitListener() {
+ commander.onQuit( new QuitListener() {
@Override
public void execute() {
needQuit = true;
}
} );
- commander.setUserMoveListener(new UserMoveListener() {
+ commander.onUserMove( new UserMoveListener() {
@Override
public void execute() {
playerMovedListener.onPlayerMoved( null );
}
- });
+ } );
- commander.setGoListener(new GoListener() {
+ commander.onGo( new GoListener() {
@Override
public void execute() {
playerMovedListener.onPlayerMoved( null );
}
- });
+ } );
- commander.setProtoverListener(new ProtoverListener() {
+ commander.onProtover( new ProtoverListener() {
@Override
public void execute( int protocolVersion ) {
commander.enableUserMovePrefixes();
@@ -76,7 +76,7 @@ public void execute( int protocolVersion ) {
logger.info( "Protocol version detected = " + protocolVersion );
}
- });
+ } );
//critically important to send this sequence at the start
//to ensure the Winboard won't ignore our 'setfeature' commands
View
22 src/test/java/com/leokom/chess/gui/winboard/WinBoardCommanderReceiveTest.java
@@ -17,7 +17,7 @@ public void xboard() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final XBoardListener listener = mock( XBoardListener.class );
- commander.setXboardListener( listener );
+ commander.onXBoard( listener );
commander.processInputFromServer();
@@ -30,7 +30,7 @@ public void opponentOffersDraw() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final OfferDrawListener listener = mock( OfferDrawListener.class );
- commander.setOfferDrawListener( listener );
+ commander.onOfferDraw( listener );
commander.processInputFromServer();
@@ -46,7 +46,7 @@ public void userMove() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final UserMoveListener listener = mock( UserMoveListener.class );
- commander.setUserMoveListener( listener );
+ commander.onUserMove( listener );
commander.processInputFromServer();
@@ -59,7 +59,7 @@ public void nonGoReceived() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final GoListener listener = mock( GoListener.class );
- commander.setGoListener( listener );
+ commander.onGo( listener );
commander.processInputFromServer();
@@ -72,7 +72,7 @@ public void goReceived() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final GoListener listener = mock( GoListener.class );
- commander.setGoListener( listener );
+ commander.onGo( listener );
commander.processInputFromServer();
@@ -97,7 +97,7 @@ public void noProtoverLineSent() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final ProtoverListener listener = mock( ProtoverListener.class );
- commander.setProtoverListener( listener );
+ commander.onProtover( listener );
commander.processInputFromServer();
@@ -110,7 +110,7 @@ public void protoverLineSent() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final ProtoverListener listener = mock( ProtoverListener.class );
- commander.setProtoverListener( listener );
+ commander.onProtover( listener );
commander.processInputFromServer();
@@ -124,7 +124,7 @@ public void protoverLineWithVersionSent() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final ProtoverListener listener = mock( ProtoverListener.class );
- commander.setProtoverListener( listener );
+ commander.onProtover( listener );
commander.processInputFromServer();
@@ -149,7 +149,7 @@ public void protoverLineSentNoInputNoCalls() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final ProtoverListener listener = mock( ProtoverListener.class );
- commander.setProtoverListener( listener );
+ commander.onProtover( listener );
verify( listener, never() ).execute( anyInt() );
}
@@ -160,7 +160,7 @@ public void nonQuitLine() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final QuitListener listener = mock( QuitListener.class );
- commander.setQuitListener( listener );
+ commander.onQuit( listener );
commander.processInputFromServer();
@@ -173,7 +173,7 @@ public void quitLine() {
WinboardCommander commander = new WinboardCommanderImpl( communicator );
final QuitListener listener = mock( QuitListener.class );
- commander.setQuitListener( listener );
+ commander.onQuit( listener );
commander.processInputFromServer();
View
8 src/test/java/com/leokom/chess/gui/winboard/WinBoardPlayerTest.java
@@ -55,7 +55,7 @@ public void quitCommandSwitchesShutdownNeed() {
WinboardPlayer controller = new WinboardPlayer( commander );
ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
- verify( commander ).setQuitListener( quitListener.capture() );
+ verify( commander ).onQuit( quitListener.capture() );
assertFalse( controller.needShuttingDown() );
@@ -76,7 +76,7 @@ public void quitListenerActsCorrectly() {
final ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
final WinboardPlayer winboardPlayer = new WinboardPlayer( commander );
- verify( commander ).setQuitListener( quitListener.capture() );
+ verify( commander ).onQuit( quitListener.capture() );
quitListener.getValue().execute();
@@ -102,7 +102,7 @@ public void useCommanderForQuitCommandRealTest() {
private static Stubber executeQuitListener( WinboardCommander commander ) {
final ArgumentCaptor<QuitListener> quitListener = ArgumentCaptor.forClass( QuitListener.class );
- verify( commander ).setQuitListener( quitListener.capture() );
+ verify( commander ).onQuit( quitListener.capture() );
return doAnswer( new Answer() {
@Override
@@ -129,7 +129,7 @@ public void correctProtoverReaction() {
new WinboardPlayer( commander );
//the player must have set its listener in constructor...
- verify( commander ).setProtoverListener( listenerCaptor.capture() );
+ verify( commander ).onProtover( listenerCaptor.capture() );
//calling the protover listener - it must have implications described below.
listenerCaptor.getValue().execute( PROTOCOL_VERSION );
Please sign in to comment.
Something went wrong with that request. Please try again.