1 package net.sf.openrocket.communication;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
7 import net.sf.openrocket.util.Prefs;
12 public class BugReportTest {
14 private HttpURLConnectionMock setup() {
15 HttpURLConnectionMock connection = new HttpURLConnectionMock();
16 Communicator.setConnectionSource(new ConnectionSourceStub(connection));
18 connection.setUseCaches(true);
22 private void check(HttpURLConnectionMock connection) {
23 assertEquals(Communicator.BUG_REPORT_URL, connection.getTrueUrl());
24 assertTrue(connection.getConnectTimeout() > 0);
25 assertEquals(Prefs.getVersion(), connection.getRequestProperty("X-OpenRocket-Version"));
26 assertTrue(connection.getInstanceFollowRedirects());
27 assertEquals("POST", connection.getRequestMethod());
28 assertFalse(connection.getUseCaches());
33 public void testBugReportSuccess() throws IOException {
34 HttpURLConnectionMock connection = setup();
35 connection.setResponseCode(Communicator.BUG_REPORT_RESPONSE_CODE);
42 BugReporter.sendBugReport(message);
46 String msg = connection.getOutputStreamString();
47 assertTrue(msg.indexOf("version=" + Prefs.getVersion()) >= 0);
48 assertTrue(msg.indexOf(Communicator.encode(message)) >= 0);
53 public void testBugReportFailure() throws IOException {
54 HttpURLConnectionMock connection = setup();
55 connection.setResponseCode(200);
63 BugReporter.sendBugReport(message);
64 fail("Exception did not occur");
65 } catch (IOException e) {