Skip to content
Snippets Groups Projects
Commit 9c310df7 authored by dgelessus's avatar dgelessus
Browse files

Inline IServerConnection (we have no tests for this anyway...)

parent 4f4ca553
No related branches found
No related tags found
No related merge requests found
/**
* (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, Heinrich
* Heine Universitaet Duesseldorf This software is licenced under EPL 1.0
* (http://www.eclipse.org/org/documents/epl-v10.html)
* */
package de.prob.core;
import java.io.File;
import de.prob.cli.CliException;
import de.prob.exceptions.ProBException;
/**
* This interface can be used to mock up a connection to ProB for testing. Don't
* use this in productive code.
*
* An example of such a mock is
*
* <pre>
* IServerConnection mock = EasyMock.createMock(IServerConnection.class);
* mock.startup();
* EasyMock.expect(mock.sendCommand(COMMAND)).andReturn(
* ProBResultParser.parse(EXPECTED_ANSWER));
* GetErrorsHelper.expectGetErrors(mock);
* EasyMock.replay(mock);
* Animator animator = new AnimatorImpl(mock);
* EasyMock.verify(mock);
* // [ ... Assertions ...]
* </pre>
*
* @author Jens Bendisposto
*
*/
public interface IServerConnection {
public abstract int getCliPortNumber();
public abstract String sendCommand(final String commandString)
throws ProBException;
public abstract void shutdown();
public abstract void startup(File file) throws CliException;
void sendUserInterruptSignal();
}
\ No newline at end of file
......@@ -11,7 +11,6 @@ import java.util.List;
import java.util.Map;
import de.prob.cli.CliException;
import de.prob.core.IServerConnection;
import de.prob.core.LanguageDependendAnimationPart;
import de.prob.core.ProblemHandler;
import de.prob.core.command.CommandException;
......@@ -38,7 +37,7 @@ public class AnimatorImpl {
private final History history = new History();
private IServerConnection connector;
private ServerConnection connector;
private MachineDescription description;
......@@ -46,8 +45,7 @@ public class AnimatorImpl {
private LanguageDependendAnimationPart langdep;
public AnimatorImpl(final IServerConnection serverConnection,
final File file) {
public AnimatorImpl(final ServerConnection serverConnection, final File file) {
this.file = file;
setConnector(serverConnection);
}
......@@ -92,8 +90,7 @@ public class AnimatorImpl {
return history;
}
private synchronized void setConnector(
final IServerConnection serverConnection) {
private synchronized void setConnector(final ServerConnection serverConnection) {
this.connector = serverConnection;
try {
connector.startup(file);
......
......@@ -16,13 +16,11 @@ import java.nio.charset.Charset;
import de.prob.cli.CliException;
import de.prob.cli.CliStarter;
import de.prob.core.IServerConnection;
import de.prob.core.ProblemHandler;
import de.prob.exceptions.ProBException;
import de.prob.logging.Logger;
public class ServerConnection implements IServerConnection {
public class ServerConnection {
private Socket socket = null;
private BufferedInputStream inputStream = null;
private PrintStream outputStream = null;
......@@ -66,7 +64,6 @@ public class ServerConnection implements IServerConnection {
}
}
@Override
public String sendCommand(final String commandString) throws ProBException {
if (shutdown) {
final String message = "probcli is currently shutting down";
......@@ -156,7 +153,6 @@ public class ServerConnection implements IServerConnection {
return result.length() > 0 ? result.toString() : null;
}
@Override
public void startup(final File file) throws CliException {
if (shutdown) {
startcli(file);
......@@ -168,7 +164,6 @@ public class ServerConnection implements IServerConnection {
}
}
@Override
public void shutdown() {
if (!shutdown) {
if (socket != null) {
......@@ -195,12 +190,10 @@ public class ServerConnection implements IServerConnection {
}
}
@Override
public int getCliPortNumber() {
return cli.getPort();
}
@Override
public void sendUserInterruptSignal() {
if (cli != null) {
cli.sendUserInterruptReference();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment