@Test public void lightService_requestFavourites() { List<LightModel> lights = new ArrayList<>(); mockClient(); when(lightRepository.findFavourites()).thenReturn(Observable.just(lights)); TestSubscriber<List<LightModel>> tester = new TestSubscriber<>(); lightService.requestFavourites().subscribe(tester); tester.assertValue(lights); tester.assertCompleted(); tester.assertNoErrors(); }
@Test public void lightService_delete() { String LIGHT_UUID = "myUuid"; when(lightRepository.delete(LIGHT_UUID)).thenReturn(Observable.just(null)); TestSubscriber<Void> tester = new TestSubscriber<>(); lightService.delete(LIGHT_UUID).subscribe(tester); verify(lightRepository).delete(LIGHT_UUID); tester.assertCompleted(); tester.assertNoErrors(); }
@Test public void lightService_update() { LightModel lightModel = new LightModel(); when(lightRepository.update(lightModel)).thenReturn(Observable.just(null)); TestSubscriber<Void> tester = new TestSubscriber<>(); lightService.update(lightModel).subscribe(tester); verify(lightRepository).update(lightModel); tester.assertCompleted(); tester.assertNoErrors(); }
@Test public void lightService_requestByEnvironment() { Integer ENVIRONMENT = 108; List<LightModel> lights = new ArrayList<>(); mockClient(); when(lightRepository.findByEnvironment(ENVIRONMENT)).thenReturn(Observable.just(lights)); TestSubscriber<List<LightModel>> tester = new TestSubscriber<>(); lightService.requestByEnvironment(ENVIRONMENT).subscribe(tester); tester.assertValue(lights); tester.assertCompleted(); tester.assertNoErrors(); }
@Test public void lightService_add() { String LIGHT_UUID = "myUuid"; LightModel lightModel = new LightModel(); when(lightRepository.add(lightModel)).thenReturn(Observable.just(LIGHT_UUID)); TestSubscriber<String> tester = new TestSubscriber<>(); lightService.add(lightModel).subscribe(tester); verify(lightRepository).add(lightModel); tester.assertValue(LIGHT_UUID); tester.assertCompleted(); tester.assertNoErrors(); }