UUIDStore { public Observable<String> get() { if(store.isEmpty()) { return generateUUIDAndStore(); } return store.get(); } UUIDStore(Context context); Observable<String> get();  }
@Test public void getsFromInternalStore() { Observable<String> internalObservable = Observable.just("uuid"); when(internalStore.get()).thenReturn(internalObservable); TestSubscriber<String> ts = new TestSubscriber<>(); store.get().subscribe(ts); assertThat(ts.getOnNextEvents(), hasItems("uuid")); }
@Test public void whenEmptyUUIDIsGenerated () { when(internalStore.isEmpty()).thenReturn(true); when(internalStore.get()).thenReturn(Observable.just("uuid")); TestSubscriber<String> ts = new TestSubscriber<>(); store.get().subscribe(ts); assertThat(ts.getOnNextEvents().size(), equalTo(1)); verify(internalStore).store(); }
@Test public void whenEmptyUUIDIsStored () { Observable<String> internalObservable = Observable.empty(); when(internalStore.isEmpty()).thenReturn(true); when(internalStore.get()).thenReturn(internalObservable); store.get().subscribe(); verify(storeFunc).call(anyString()); }