class FieldCommand extends AbstractCommand {

	@Override
	public void execute(String commandName, BufferedReader reader, BufferedWriter writer)
			throws Py4JException, IOException {
		String returnCommand = null;
		String subCommand = safeReadLine(reader, false);

		if (subCommand.equals(FIELD_GET_SUB_COMMAND_NAME)) {
			returnCommand = getField(reader);
		} else if (subCommand.equals(FIELD_SET_SUB_COMMAND_NAME)) {
			returnCommand = setField(reader);
		} else {
			returnCommand = Protocol.getOutputErrorCommand("Unknown Field SubCommand Name: " + subCommand);
		}
		logger.finest("Returning command: " + returnCommand);
		writer.write(returnCommand);
		writer.flush();
	}

}

class FieldCommandTest {

	private ExampleEntryPoint entryPoint;
	private Gateway gateway;
	private FieldCommand command;
	private BufferedWriter writer;
	private StringWriter sWriter;
	private String target;

	@Test
	public void testSetFieldObject() {

		String objectId = gateway.putNewObject(new StringBuffer("Hello"));
		String inputCommand = "s\n" + target + "\nfield20\nr" + objectId + "\ne\n";
		try {
			command.execute("f", new BufferedReader(new StringReader(inputCommand)), writer);
			assertEquals("!yv\n", sWriter.toString());
			assertEquals(((ExampleClass) gateway.getObject(target)).field20, gateway.getObject(objectId));
		} catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}

}