ArrayCommand extends AbstractCommand { private String createArray(BufferedReader reader) throws IOException { String fqn = (String) Protocol.getObject(reader.readLine(), gateway); List<Object> dimensions = getArguments(reader); int size = dimensions.size(); int[] dimensionsInt = new int[size]; for (int i = 0; i < size; i++) { dimensionsInt[i] = (Integer) dimensions.get(i); } Object newArray = gateway.getReflectionEngine().createArray(fqn, dimensionsInt); ReturnObject returnObject = gateway.getReturnObject(newArray); return Protocol.getOutputCommand(returnObject); } ArrayCommand(); @Override void execute(String commandName, BufferedReader reader, BufferedWriter writer); static final String ARRAY_COMMAND_NAME; static final char ARRAY_GET_SUB_COMMAND_NAME; static final char ARRAY_SET_SUB_COMMAND_NAME; static final char ARRAY_SLICE_SUB_COMMAND_NAME; static final char ARRAY_LEN_SUB_COMMAND_NAME; static final char ARRAY_CREATE_SUB_COMMAND_NAME; static final String RETURN_VOID; }
@Test public void testCreateArray() { String inputCommand = ArrayCommand.ARRAY_CREATE_SUB_COMMAND_NAME + "\nsint\ni3\ne\n"; try { command.execute("a", new BufferedReader(new StringReader(inputCommand)), writer); int[] intarray = (int[]) gateway.getObject("o2"); assertEquals(3, intarray.length); inputCommand = ArrayCommand.ARRAY_CREATE_SUB_COMMAND_NAME + "\nsjava.lang.String\ni3\ni5\ne\n"; command.execute("a", new BufferedReader(new StringReader(inputCommand)), writer); String[][] stringarray = (String[][]) gateway.getObject("o3"); assertEquals(3, stringarray.length); assertEquals(5, stringarray[0].length); } catch (Exception e) { e.printStackTrace(); fail(); } }