@Test
  public void testResumeNext() {
    Subscription s = mock(Subscription.class);
    // Trigger failure on second element
    TestObservable f = new TestObservable(s, "one", "fail", "two", "three");
    Observable<String> w = Observable.create(f);
    Observable<String> resume = Observable.from("twoResume", "threeResume");
    Observable<String> observable = Observable.create(onErrorResumeNextViaObservable(w, resume));

    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    observable.subscribe(observer);

    try {
      f.t.join();
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }

    verify(observer, Mockito.never()).onError(any(Throwable.class));
    verify(observer, times(1)).onCompleted();
    verify(observer, times(1)).onNext("one");
    verify(observer, Mockito.never()).onNext("two");
    verify(observer, Mockito.never()).onNext("three");
    verify(observer, times(1)).onNext("twoResume");
    verify(observer, times(1)).onNext("threeResume");
  }
  @Test
  public void testMapResumeAsyncNext() {
    Subscription sr = mock(Subscription.class);
    // Trigger multiple failures
    Observable<String> w = Observable.from("one", "fail", "two", "three", "fail");
    // Resume Observable is async
    TestObservable f = new TestObservable(sr, "twoResume", "threeResume");
    Observable<String> resume = Observable.create(f);

    // Introduce map function that fails intermittently (Map does not prevent this when the observer
    // is a
    //  rx.operator incl onErrorResumeNextViaObservable)
    w =
        w.map(
            new Func1<String, String>() {
              public String call(String s) {
                if ("fail".equals(s)) throw new RuntimeException("Forced Failure");
                System.out.println("BadMapper:" + s);
                return s;
              }
            });

    Observable<String> observable = Observable.create(onErrorResumeNextViaObservable(w, resume));

    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    observable.subscribe(observer);

    try {
      f.t.join();
    } catch (InterruptedException e) {
      fail(e.getMessage());
    }

    verify(observer, Mockito.never()).onError(any(Throwable.class));
    verify(observer, times(1)).onCompleted();
    verify(observer, times(1)).onNext("one");
    verify(observer, Mockito.never()).onNext("two");
    verify(observer, Mockito.never()).onNext("three");
    verify(observer, times(1)).onNext("twoResume");
    verify(observer, times(1)).onNext("threeResume");
  }
  public RelevantCommunityAnalyser(IIdentity linkedEntity, String linkType) {
    if (linkType.equals("CSS")) this.linkedCss = linkedEntity;
    // else
    //	this.linkedDomain = linkedEntity;

    proximityHistory = new ArrayList<ProximityRecord>();
    recordedMetadata = new HashMap<String, String>();
    refusals = new ArrayList<ICisProposal>();

    try {
      List<CtxIdentifier> ctxMetadata =
          userContextBroker.lookup(CtxModelType.ATTRIBUTE, "hasCLM").get();

      for (int i = 0; i < ctxMetadata.size(); i++) {
        CtxAttribute thisMetadata =
            (CtxAttribute) userContextBroker.retrieve(ctxMetadata.get(i)).get();
        String thisMetadataValue = thisMetadata.getStringValue();
        recordedMetadata.put(
            thisMetadataValue.split("---")[0].split("CIS ID: ")[1],
            thisMetadataValue.split("---")[1]);
      }
    } catch (InterruptedException e) {

      e.printStackTrace();
    } catch (ExecutionException e) {

      e.printStackTrace();
    } catch (CtxException e) {

      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    }

    // new ProximityRecordingThread().start();
  }