Java tutorial
package com.conwet.xjsp.features; /* * #%L * eXtensible JSON Streaming Protocol * %% * Copyright (C) 2011 - 2014 CoNWeT Lab., Universidad Politcnica de Madrid * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ import org.json.simple.JSONObject; import org.junit.Test; import org.mockito.ArgumentCaptor; import static org.mockito.Mockito.*; import static org.assertj.core.api.Assertions.*; /** * * @author sortega */ public class DefaultXJSPHandlerTest { @Test @SuppressWarnings("unchecked") public void shouldParseErrorMessages() throws Exception { System.out.println("should parse error messages"); // Given JSONObject payload = new JSONObject(); payload.put("id", "1234"); payload.put("message", "msg"); payload.put("code", 301l); Message message = new ImmutableMessage("xjsp", "error", payload, "1"); Session session = mock(Session.class); // Do DefaultXJSPHandler instance = spy(new DefaultXJSPHandler()); instance.handleMessage(message, session); // Assert ArgumentCaptor<ErrorMessage> error = ArgumentCaptor.forClass(ErrorMessage.class); verify(instance).doHandleError(error.capture(), eq(session)); assertThat(error.getValue().getCode()).isEqualTo(301L); assertThat(error.getValue().getSourceId()).isEqualTo("1234"); assertThat(error.getValue().getMessage()).isEqualTo("msg"); } }