ServerDataSource implements FederatedNetworkDataSource { @Override public Observable<Boolean> sendGradient(byte[] gradient) { NetworkModel networkModel = mapper.toNetworkModel(gradient); RequestBody requestBody = RequestBody .create(MediaType.parse("application/octet-stream"), networkModel.getGradient()); return networkService.uploadGradient(requestBody); } ServerDataSource(ServerService networkService, NetworkMapper mapper); @Override Observable<Boolean> sendGradient(byte[] gradient); @Override Observable<byte[]> retrieveGradient(); @Override Observable<Integer> registerModel();  }
@Test public void testSendGradient() { byte[] gradient = new byte[]{}; NetworkModel networkModel = mock(NetworkModel.class); NetworkMapper mapper = mock(NetworkMapper.class); given(mapper.toNetworkModel(gradient)).willReturn(networkModel); given(networkModel.getGradient()).willReturn(gradient); ServerService networkService = mock(ServerService.class); ServerDataSource dataSource = new ServerDataSource(networkService, mapper); dataSource.sendGradient(gradient); verify(mapper).toNetworkModel(gradient); verify(networkService).uploadGradient(any(RequestBody.class)); }