Skip to content

Commit

Permalink
Fix MemoryStoreCore to use fromIterable (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoi committed Dec 28, 2017
1 parent ef244e3 commit 786bc4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public Maybe<U> getCached(@NonNull final T id) {
@NonNull
@Override
public Single<List<U>> getCached() {
return Observable.fromCallable(() -> cache.keySet().iterator())
return Observable.fromIterable(cache.keySet())
.map(cache::get)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import io.reactivex.Observable;
import io.reactivex.observers.TestObserver;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

public class MemoryStoreCoreTest {

private MemoryStoreCore<Integer, String> memoryStoreCore;
Expand Down Expand Up @@ -148,6 +151,44 @@ public void delete_DoesNotTriggerStream() {
.assertNoValues();
}

@Test
public void getCached_ReturnsAllValues() {
memoryStoreCore.put(100, "test value 1");
memoryStoreCore.put(200, "test value 2");

memoryStoreCore.getCached()
.test()
.assertValue(asList("test value 1", "test value 2"));
}

@Test
public void getCached_WhenEmptyStore_ReturnsEmptyList() {
memoryStoreCore.getCached()
.test()
.assertValue(emptyList());
}

@Test
public void getCached_WithId_ReturnsValue() {
memoryStoreCore.put(100, "test value 1");
memoryStoreCore.put(200, "test value 2");

memoryStoreCore.getCached(200)
.test()
.assertValue("test value 2");
}

@Test
public void getCached_WithId_WhenNoValue_Completes() {
memoryStoreCore.put(100, "test value 1");
memoryStoreCore.put(200, "test value 2");

memoryStoreCore.getCached(300)
.test()
.assertComplete()
.assertNoValues();
}

@Test
public void getStream_WithNoId_EmitsAllValues_AndDoesNotComplete() {
TestObserver<String> testObserver = new TestObserver<>();
Expand Down

0 comments on commit 786bc4d

Please sign in to comment.