@Test(expected = NullPointerException.class) public void toMultimapValueNull() { just1.toMultimap(new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, null); }
@Test(expected = NullPointerException.class) public void toMultimapKeyNull() { just1.toMultimap(null); }
@Test(expected = NullPointerException.class) public void toMultimapMapMapSupplierNull() { just1.toMultimap(new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, null); }
@Test(expected = NullPointerException.class) public void toMultimapMapMapCollectionSupplierNull() { just1.toMultimap(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) { return v; } }, new Function<Integer, Integer>() { @Override public Integer apply(Integer v) { return v; } }, new Callable<Map<Integer, Collection<Integer>>>() { @Override public Map<Integer, Collection<Integer>> call() { return new HashMap<Integer, Collection<Integer>>(); } }, null); }
@Test public void testToMultimapWithValueSelector() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc, duplicate); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); mapped.subscribe(singleObserver); verify(singleObserver, never()).onError(any(Throwable.class)); verify(singleObserver, times(1)).onSuccess(expected); }
@Test public void testToMultimap() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); mapped.subscribe(singleObserver); verify(singleObserver, never()).onError(any(Throwable.class)); verify(singleObserver, times(1)).onSuccess(expected); }
@Test public void testToMultimapFlowable() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Flowable<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc).toFlowable(); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); mapped.subscribe(objectSubscriber); verify(objectSubscriber, never()).onError(any(Throwable.class)); verify(objectSubscriber, times(1)).onNext(expected); verify(objectSubscriber, times(1)).onComplete(); }
@Test public void testToMultimapWithValueSelectorFlowable() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Flowable<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc, duplicate).toFlowable(); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); mapped.subscribe(objectSubscriber); verify(objectSubscriber, never()).onError(any(Throwable.class)); verify(objectSubscriber, times(1)).onNext(expected); verify(objectSubscriber, times(1)).onComplete(); }
@Test public void testToMultimapWithError() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Function<String, Integer> lengthFuncErr = new Function<String, Integer>() { @Override public Integer apply(String t1) { if ("b".equals(t1)) { throw new RuntimeException("Forced Failure"); } return t1.length(); } }; Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFuncErr); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); mapped.subscribe(singleObserver); verify(singleObserver, times(1)).onError(any(Throwable.class)); verify(singleObserver, never()).onSuccess(expected); }
@Test public void testToMultimapWithErrorInValueSelector() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Function<String, String> duplicateErr = new Function<String, String>() { @Override public String apply(String t1) { if ("b".equals(t1)) { throw new RuntimeException("Forced failure"); } return t1 + t1; } }; Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc, duplicateErr); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); mapped.subscribe(singleObserver); verify(singleObserver, times(1)).onError(any(Throwable.class)); verify(singleObserver, never()).onSuccess(expected); }
@Test public void testToMultimapWithMapThrowingFactory() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); Callable<Map<Integer, Collection<String>>> mapFactory = new Callable<Map<Integer, Collection<String>>>() { @Override public Map<Integer, Collection<String>> call() { throw new RuntimeException("Forced failure"); } }; Single<Map<Integer, Collection<String>>> mapped = source .toMultimap(lengthFunc, new Function<String, String>() { @Override public String apply(String v) { return v; } }, mapFactory); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); mapped.subscribe(singleObserver); verify(singleObserver, times(1)).onError(any(Throwable.class)); verify(singleObserver, never()).onSuccess(expected); }
@Test public void testToMultimapWithErrorFlowable() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Function<String, Integer> lengthFuncErr = new Function<String, Integer>() { @Override public Integer apply(String t1) { if ("b".equals(t1)) { throw new RuntimeException("Forced Failure"); } return t1.length(); } }; Flowable<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFuncErr).toFlowable(); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("a", "b")); expected.put(2, Arrays.asList("cc", "dd")); mapped.subscribe(objectSubscriber); verify(objectSubscriber, times(1)).onError(any(Throwable.class)); verify(objectSubscriber, never()).onNext(expected); verify(objectSubscriber, never()).onComplete(); }
@Test public void testToMultimapWithErrorInValueSelectorFlowable() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd"); Function<String, String> duplicateErr = new Function<String, String>() { @Override public String apply(String t1) { if ("b".equals(t1)) { throw new RuntimeException("Forced failure"); } return t1 + t1; } }; Flowable<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc, duplicateErr).toFlowable(); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(1, Arrays.asList("aa", "bb")); expected.put(2, Arrays.asList("cccc", "dddd")); mapped.subscribe(objectSubscriber); verify(objectSubscriber, times(1)).onError(any(Throwable.class)); verify(objectSubscriber, never()).onNext(expected); verify(objectSubscriber, never()).onComplete(); }
@Test(expected = NullPointerException.class) public void toMultimapMapSupplierReturnsNull() { just1.toMultimap(new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, new Callable<Map<Object, Collection<Object>>>() { @Override public Map<Object, Collection<Object>> call() { return null; } }).blockingGet(); }
@Test public void testToMultimapWithMapThrowingFactoryFlowable() { Flowable<String> source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); Callable<Map<Integer, Collection<String>>> mapFactory = new Callable<Map<Integer, Collection<String>>>() { @Override public Map<Integer, Collection<String>> call() { throw new RuntimeException("Forced failure"); } }; Flowable<Map<Integer, Collection<String>>> mapped = source .toMultimap(lengthFunc, new Function<String, String>() { @Override public String apply(String v) { return v; } }, mapFactory).toFlowable(); Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>(); expected.put(2, Arrays.asList("cc", "dd")); expected.put(3, Arrays.asList("eee", "fff")); mapped.subscribe(objectSubscriber); verify(objectSubscriber, times(1)).onError(any(Throwable.class)); verify(objectSubscriber, never()).onNext(expected); verify(objectSubscriber, never()).onComplete(); }
@Test(expected = NullPointerException.class) public void toMultimapMapCollectionSupplierReturnsNull() { just1.toMultimap(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) { return v; } }, new Function<Integer, Integer>() { @Override public Integer apply(Integer v) { return v; } }, new Callable<Map<Integer, Collection<Integer>>>() { @Override public Map<Integer, Collection<Integer>> call() { return new HashMap<Integer, Collection<Integer>>(); } }, new Function<Integer, Collection<Integer>>() { @Override public Collection<Integer> apply(Integer v) { return null; } }).blockingGet(); }
@Override public Publisher<Map<Integer, Collection<Integer>>> createPublisher(final long elements) { return Flowable.range(1, 1000).toMultimap(Functions.<Integer>identity()).toFlowable() ; }
.toMultimap(lengthFunc, identity, mapSupplier, collectionFactory).toFlowable();
Callable<Map<K, Collection<V>>> mapSupplier = HashMapSupplier.asCallable(); Function<K, List<V>> collectionFactory = ArrayListSupplier.asFunction(); return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory);
Callable<Map<K, Collection<T>>> mapSupplier = HashMapSupplier.asCallable(); Function<K, List<T>> collectionFactory = ArrayListSupplier.asFunction(); return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory);