ConstructorCommand extends AbstractCommand { @Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String fqn = reader.readLine(); List<Object> arguments = getArguments(reader); ReturnObject returnObject = invokeConstructor(fqn, arguments); String returnCommand = Protocol.getOutputCommand(returnObject); logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); } ConstructorCommand(); @Override void execute(String commandName, BufferedReader reader, BufferedWriter writer); final static String CONSTRUCTOR_COMMAND_NAME; }
@Test public void testConstructor0Arg() { String inputCommand = "py4j.examples.ExampleClass\ne\n"; try { command.execute("i", new BufferedReader(new StringReader(inputCommand)), writer); assertEquals("!yro0\n", sWriter.toString()); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testConstructor1Arg() { String inputCommand = "py4j.examples.ExampleClass\ni5\ne\n"; try { command.execute("i", new BufferedReader(new StringReader(inputCommand)), writer); assertEquals("!yro0\n", sWriter.toString()); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testDefaultConstructor() { String inputCommand = "py4j.examples.Stack\ne\n"; try { command.execute("i", new BufferedReader(new StringReader(inputCommand)), writer); assertEquals("!yro0\n", sWriter.toString()); assertTrue(gateway.getObject("o0") instanceof Stack); } catch (Exception e) { e.printStackTrace(); fail(); } }
@Test public void testWrongConstructor() { String inputCommand = "py4j.examples.Stack\ni5\ne\n"; try { command.execute("i", new BufferedReader(new StringReader(inputCommand)), writer); assertTrue(sWriter.toString().startsWith("!x")); } catch (Exception e) { e.printStackTrace(); fail(); } }