### Question:
ListJsonAction extends AbstractJsonAction { @Override public void execute() throws ServletException, IOException, ActionException { getContext().setContentType("application/json"); ArrayJS arrayJS = new ArrayJS(); SimonVisitors.visitList(getContext().getManager(), pattern, types, new SimonVisitorImpl(arrayJS)); arrayJS.write(getContext().getWriter()); } ListJsonAction(ActionContext context); String getPattern(); void setPattern(String pattern); @Override void readParameters(); @Override void execute(); static final String PATH; }### Answer:
@Test public void testExecute() throws Exception { TestActionContext context = new TestActionContext("/data/table.json"); ListJsonAction action = new ListJsonAction(context); action.readParameters(); action.execute(); assertEquals(context.getContentType(), "application/json"); String json = context.toString(); JSONTokener jsonTokener = new JSONTokener(json); Set<String> names = new HashSet<>(); names.add("A"); names.add("B"); names.add("C"); Object object = jsonTokener.nextValue(); if (object instanceof JSONArray) { JSONArray jsonArray = (JSONArray) object; for (int i = 0; i < jsonArray.length(); i++) { object = jsonArray.get(i); if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject) object; String name = jsonObject.getString("name"); names.remove(name); } } } assertTrue(names.isEmpty()); }