### Question:
ServerResponseProcessor { public void process(final String jsonString) { try { final JSONObject jsonObject = new JSONObject(jsonString); if (jsonObject.has("locations")) { otherUsersLocationModel.setFromJson(jsonObject.getJSONObject("locations")); } if (jsonObject.has("locations")) { chatModel.setFromJson(jsonObject.getJSONObject("chatMessages")); } eventBus.post(Events.NEW_SERVER_RESPONSE_EVENT); } catch (Exception e) { Timber.d(e); } } @Inject  ServerResponseProcessor(OtherUsersLocationModel otherUsersLocationModel, EventBus eventBus, ChatModel chatModel); void process(final String jsonString);  }### Answer:
@Test public void process_chatmessagesAreSetOnModel() throws IOException, URISyntaxException, JSONException { final String json = AXT.at(new File(getClass().getClassLoader() .getResource("simple_server_response.json").toURI())).readToString(); final ChatModel chatModel = mock(ChatModel.class); final ServerResponseProcessor tested = new ServerResponseProcessor( mock(OtherUsersLocationModel.class), mock(EventBus.class), chatModel); tested.process(json); verify(chatModel).setFromJson(any(JSONObject.class)); }
@Test public void process_eventIsFiredForValidJSON() throws IOException, URISyntaxException { final String json = AXT.at(new File(getClass().getClassLoader() .getResource("simple_server_response.json").toURI())).readToString(); final EventBus eventMock = mock(EventBus.class); final ServerResponseProcessor tested = new ServerResponseProcessor( mock(OtherUsersLocationModel.class), eventMock, mock(ChatModel.class)); tested.process(json); verify(eventMock, times(1)).post(Events.NEW_SERVER_RESPONSE_EVENT); }
@Test public void process_noEventIsFiredForInvalidJSON() { final EventBus eventMock = mock(EventBus.class); final ServerResponseProcessor tested = new ServerResponseProcessor( mock(OtherUsersLocationModel.class), eventMock, mock(ChatModel.class)); tested.process("borken"); verify(eventMock, never()).post(Events.NEW_SERVER_RESPONSE_EVENT); }