@Test
public void testToMapWithError() {

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