@Test(timeout = 1000L) public void setsNetworkState() throws Exception { StubDropHttp dropStub = new StubDropHttp(); dropStub.messages.setData(new ArrayList<>()); connector = new HttpDropConnector(networkStatus, dropStub); networkStatus.online(); dropStub.messages.setResponseCode(0); connector.receive(identity, new Date(0L)); assertFalse(networkStatus.isOnline()); dropStub.messages.setResponseCode(204); connector.receive(identity, new Date(0L)); assertTrue(networkStatus.isOnline()); }
@Override public DropPollResponse receive(Identity i, Date since) { DropURL d = convertCollectionIntoDropUrl(i.getDropUrls()); try { HTTPResult<Collection<byte[]>> result = receiveMessages(since, d); if (result.getResponseCode() == 0) { networkStatus.offline(); } else { networkStatus.online(); } return createDropMessagesFromHttpResult(result, i); } catch (IOException e) { logger.error("failed to poll drop: " + e.getMessage(), e); networkStatus.offline(); throw new IllegalStateException("failed to poll drop, cannot continue", e); } }
HttpDropConnector implements DropConnector { @Override public DropPollResponse receive(Identity i, Date since) { DropURL d = convertCollectionIntoDropUrl(i.getDropUrls()); try { HTTPResult<Collection<byte[]>> result = receiveMessages(since, d); if (result.getResponseCode() == 0) { networkStatus.offline(); } else { networkStatus.online(); } return createDropMessagesFromHttpResult(result, i); } catch (IOException e) { logger.error("failed to poll drop: " + e.getMessage(), e); networkStatus.offline(); throw new IllegalStateException("failed to poll drop, cannot continue", e); } } }
HttpDropConnector implements DropConnector { @Override public DropPollResponse receive(Identity i, Date since) { DropURL d = convertCollectionIntoDropUrl(i.getDropUrls()); try { HTTPResult<Collection<byte[]>> result = receiveMessages(since, d); if (result.getResponseCode() == 0) { networkStatus.offline(); } else { networkStatus.online(); } return createDropMessagesFromHttpResult(result, i); } catch (IOException e) { logger.error("failed to poll drop: " + e.getMessage(), e); networkStatus.offline(); throw new IllegalStateException("failed to poll drop, cannot continue", e); } } HttpDropConnector(NetworkStatus networkStatus, DropHTTP dHTTP); }
HttpDropConnector implements DropConnector { @Override public DropPollResponse receive(Identity i, Date since) { DropURL d = convertCollectionIntoDropUrl(i.getDropUrls()); try { HTTPResult<Collection<byte[]>> result = receiveMessages(since, d); if (result.getResponseCode() == 0) { networkStatus.offline(); } else { networkStatus.online(); } return createDropMessagesFromHttpResult(result, i); } catch (IOException e) { logger.error("failed to poll drop: " + e.getMessage(), e); networkStatus.offline(); throw new IllegalStateException("failed to poll drop, cannot continue", e); } } HttpDropConnector(NetworkStatus networkStatus, DropHTTP dHTTP); @Override void send(Contact c, DropMessage d); @Override DropPollResponse receive(Identity i, Date since); }
HttpDropConnector implements DropConnector { @Override public DropPollResponse receive(Identity i, Date since) { DropURL d = convertCollectionIntoDropUrl(i.getDropUrls()); try { HTTPResult<Collection<byte[]>> result = receiveMessages(since, d); if (result.getResponseCode() == 0) { networkStatus.offline(); } else { networkStatus.online(); } return createDropMessagesFromHttpResult(result, i); } catch (IOException e) { logger.error("failed to poll drop: " + e.getMessage(), e); networkStatus.offline(); throw new IllegalStateException("failed to poll drop, cannot continue", e); } } HttpDropConnector(NetworkStatus networkStatus, DropHTTP dHTTP); @Override void send(Contact c, DropMessage d); @Override DropPollResponse receive(Identity i, Date since);  }