summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:59:44 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-23 14:59:44 +0100
commitc4425e949d1942d7519046d276126dfab284b658 (patch)
treef36c0aeb40073317c7b12aa84ff92dcc15b045cf
parentb325d4005793d5f147b4eb539ae7f4fa5e5fb813 (diff)
Make it possible to create "fake" clients on Android.
Extract interface from Client.ClientInterface in order to override it for Android, while still using the VariableFactory code as-is.
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java10
-rw-r--r--same/src/main/java/com/orbekk/same/VariableFactory.java6
-rw-r--r--same/src/main/java/com/orbekk/same/http/StateServlet.java6
-rw-r--r--same/src/test/java/com/orbekk/same/VariableFactoryTest.java4
4 files changed, 15 insertions, 11 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 3799041..244a64d 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -20,16 +20,18 @@ public class Client implements DiscoveryListener {
new ArrayList<StateChangedListener>();
private NetworkNotificationListener networkListener;
- public class ClientInterface {
- private ClientInterface() {
+ public class ClientInterfaceImpl implements ClientInterface {
+ private ClientInterfaceImpl() {
}
/** Get a copy of all the client state.
*/
+ @Override
public State getState() {
return new State(state);
}
+ @Override
public void set(String name, String data, long revision)
throws UpdateConflict {
String masterUrl = state.getDataOf(".masterUrl");
@@ -47,16 +49,18 @@ public class Client implements DiscoveryListener {
}
}
+ @Override
public void addStateListener(StateChangedListener listener) {
stateListeners.add(listener);
}
+ @Override
public void removeStateListener(StateChangedListener listener) {
stateListeners.remove(listener);
}
}
- private ClientInterface clientInterface = new ClientInterface();
+ private ClientInterface clientInterface = new ClientInterfaceImpl();
private ClientService serviceImpl = new ClientService() {
@Override
diff --git a/same/src/main/java/com/orbekk/same/VariableFactory.java b/same/src/main/java/com/orbekk/same/VariableFactory.java
index 49604c6..66e6747 100644
--- a/same/src/main/java/com/orbekk/same/VariableFactory.java
+++ b/same/src/main/java/com/orbekk/same/VariableFactory.java
@@ -16,7 +16,7 @@ import com.orbekk.same.State.Component;
*/
public class VariableFactory {
private Logger logger = LoggerFactory.getLogger(getClass());
- private Client.ClientInterface client;
+ private ClientInterface client;
private ObjectMapper mapper = new ObjectMapper();
private class VariableImpl<T> implements Variable<T>, StateChangedListener {
@@ -76,11 +76,11 @@ public class VariableFactory {
}
}
- public static VariableFactory create(Client.ClientInterface client) {
+ public static VariableFactory create(ClientInterface client) {
return new VariableFactory(client);
}
- VariableFactory(Client.ClientInterface client) {
+ VariableFactory(ClientInterface client) {
this.client = client;
}
diff --git a/same/src/main/java/com/orbekk/same/http/StateServlet.java b/same/src/main/java/com/orbekk/same/http/StateServlet.java
index 17e566d..8b4d8c5 100644
--- a/same/src/main/java/com/orbekk/same/http/StateServlet.java
+++ b/same/src/main/java/com/orbekk/same/http/StateServlet.java
@@ -12,18 +12,18 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orbekk.same.Client;
+import com.orbekk.same.ClientInterface;
import com.orbekk.same.UpdateConflict;
import com.orbekk.same.Variable;
import com.orbekk.same.VariableFactory;
public class StateServlet extends HttpServlet {
private Logger logger = LoggerFactory.getLogger(getClass());
- private Client.ClientInterface client;
+ private ClientInterface client;
private VariableFactory variableFactory;
private final static String TITLE = "State viewer";
- public StateServlet(Client.ClientInterface client,
+ public StateServlet(ClientInterface client,
VariableFactory variableFactory) {
this.client = client;
this.variableFactory = variableFactory;
diff --git a/same/src/test/java/com/orbekk/same/VariableFactoryTest.java b/same/src/test/java/com/orbekk/same/VariableFactoryTest.java
index a6efa4b..ed0a962 100644
--- a/same/src/test/java/com/orbekk/same/VariableFactoryTest.java
+++ b/same/src/test/java/com/orbekk/same/VariableFactoryTest.java
@@ -14,7 +14,7 @@ import org.junit.Before;
import org.junit.Test;
public class VariableFactoryTest {
- Client.ClientInterface client;
+ Client.ClientInterfaceImpl client;
VariableFactory vf;
State sampleState;
@@ -24,7 +24,7 @@ public class VariableFactoryTest {
@Before
public void setUp() {
- client = mock(Client.ClientInterface.class);
+ client = mock(Client.ClientInterfaceImpl.class);
vf = new VariableFactory(client);
initializeSampleState();
when(client.getState()).thenReturn(sampleState);