EnumAdapter implements IPreferenceAdapter<T> { @Nonnull @Override public Observable<T> observe(@Nonnull String key, @Nonnull T defaultValue, @Nonnull IGateway gateway) { return gateway.observeString(key, toString(defaultValue)).map(new Function<String, T>() { @Override public T apply(@NonNull String s) throws Exception { return fromString(s); } }); } EnumAdapter(@Nonnull Class<T> clazz); @Nonnull @Override Observable<T> observe(@Nonnull String key, @Nonnull T defaultValue, @Nonnull IGateway gateway); @Override void put(@Nonnull String key, @Nonnull T value, IGateway gateway); @Override Completable putSync(@Nonnull String key, @Nonnull T value, IGateway gateway);  }
@Test public void testObserve() throws Exception { when(gateway.observeString("testKey", NUMBER.ONE.name())) .thenReturn(Observable.just(NUMBER.TWO.name())); Observable<NUMBER> observable = adapter.observe("testKey", NUMBER.ONE, gateway); observable.subscribe(observer); verify(gateway).observeString("testKey", NUMBER.ONE.name()); verify(observer).onNext(NUMBER.TWO); verify(observer).onComplete(); verify(observer, never()).onError(any(Throwable.class)); }