### Question:
EmulatorTerminal implements Runnable { @VisibleForTesting String[] paramsParser(String params) { Stack<String> stack = new Stack<>(); List<String> paramsList = new ArrayList<>(); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); for (int i = 0; i < params.length(); i++) { String character = Character.valueOf(params.charAt(i)).toString(); if (character.matches("[{\"}]")) { if (!stack.empty()) { if ((character.equals("\"") && stack.peek().equals("\"")) || (character.equals("}") && stack.peek().equals("{"))) { stack.pop(); } else { stack.push(character); } } else { stack.push(character); } } byteArray.write(params.charAt(i)); if ((character.matches(" ") && stack.empty()) || i == params.length() - 1) { paramsList.add(byteArray.toString().trim().replaceAll("^\"|\"$", "")); byteArray.reset(); } } return paramsList.toArray(new String[0]); } @Inject  EmulatorTerminal(TerminalWrapper terminal, ContractManagerEmulator contractManager); static void main(String[] args); @Override void run();  }### Answer:
@Test public void input_WithJsonInput_ShouldReturnProperParamsArrayProperly() { String input = "put {\"asset_id\": \"X\", \"data\": {\"alice\": 100, \"bob\": 0}}"; String[] mockedParamsArray = { "put", "{\"asset_id\": \"X\", \"data\": {\"alice\": 100, \"bob\": 0}}" }; String[] paramsArray = emulatorTerminal.paramsParser(input); Assert.assertArrayEquals(paramsArray, mockedParamsArray); }
@Test public void input_WithSpacesInput_ShouldReturnProperParamsArrayProperly() { String input = "put \"key with space\" {\"alice\": 100, \"bob\": 0}"; String[] mockedParamsArray = {"put", "key with space", "{\"alice\": 100, \"bob\": 0}"}; String[] paramsArray = emulatorTerminal.paramsParser(input); Assert.assertArrayEquals(paramsArray, mockedParamsArray); }
@Test public void input_WithSpacesForFlagInput_ShouldReturnProperParamsArrayProperly() { String input = "database -c clusterKey -p \"partition key\" -v \"value with space\" " + "-n \"namespace of database\" -t \"table with space\""; String[] mockedParamsArray = { "database", "-c", "clusterKey", "-p", "partition key", "-v", "value with space", "-n", "namespace of database", "-t", "table with space" }; String[] paramsArray = emulatorTerminal.paramsParser(input); Assert.assertArrayEquals(paramsArray, mockedParamsArray); }