@Test
public void testToMapWithErrorInValueSelector() {

    Observable<String> source = Observable.from("a", "bb", "ccc", "dddd");
    Func1<String, String> duplicateErr = new Func1<String, String>() {
        @Override
        public String call(String t1) {
            if ("bb".equals(t1)) {
                throw new RuntimeException("Forced failure");
            }
            return t1 + t1;
        }
    };
    Observable<Map<Integer, String>> mapped = Observable.create(OperationToMap.toMap(source, lengthFunc, duplicateErr));
    Map<Integer, String> expected = new HashMap<Integer, String>();
    expected.put(1, "aa");
    expected.put(2, "bbbb");
    expected.put(3, "cccccc");
    expected.put(4, "dddddddd");
    mapped.subscribe(objectObserver);
    verify(objectObserver, never()).onNext(expected);
    verify(objectObserver, never()).onCompleted();
    verify(objectObserver, times(1)).onError(any(Throwable.class));
}