Example #1
0
    @Test
    public void testUnsubscribeAfterTake() {
      Subscription s = mock(Subscription.class);
      TestObservable w = new TestObservable(s, "one", "two", "three");

      @SuppressWarnings("unchecked")
      Observer<String> aObserver = mock(Observer.class);
      Observable<String> take = Observable.create(take(w, 1));
      take.subscribe(aObserver);

      // wait for the Observable to complete
      try {
        w.t.join();
      } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
      }

      System.out.println("TestObservable thread finished");
      verify(aObserver, times(1)).onNext("one");
      verify(aObserver, never()).onNext("two");
      verify(aObserver, never()).onNext("three");
      verify(aObserver, times(1)).onCompleted();
      verify(s, times(1)).unsubscribe();
      verifyNoMoreInteractions(aObserver);
    }
 @Test
 public void testRouteProcess() {
   FilterProcessor processor = new FilterProcessor();
   processor = spy(processor);
   try {
     processor.route();
     verify(processor, times(1)).runFilters("route");
   } catch (Throwable e) {
     e.printStackTrace();
   }
 }
    @Test
    public void testProcessZuulFilter() {
      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        processor.processZuulFilter(filter);
        verify(processor, times(1)).processZuulFilter(filter);
        verify(filter, times(1)).runFilter();

      } catch (Throwable e) {
        e.printStackTrace();
      }
    }
    @Test
    public void testErrorHttpException() {
      HttpServletRequest request = mock(HttpServletRequest.class);
      HttpServletResponse response = mock(HttpServletResponse.class);
      RequestContext.getCurrentContext().setRequest(request);
      RequestContext.getCurrentContext().setResponse(response);

      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        when(processor.runFilters("error")).thenThrow(new ZuulException("test", 400, "test"));
        when(filter.filterType()).thenReturn("post");
        processor.error();
        assertTrue(true);
      } catch (Throwable e) {
        e.printStackTrace();
        assertFalse(true);
      }
    }
 @Test
 public void variableAtShouldCallResolveObject() {
   try {
     PrimObject primObject = new PrimObject();
     PrimObjectClass primObjectClass = mock(PrimObjectClass.class);
     when(primObjectClass.indexOfVariable("Thing")).thenReturn(0);
     primObject.cls(primObjectClass);
     PrimObject spy = spy(primObject);
     spy.variableAt("Thing");
     verify(spy).resolveObject("Thing");
   } catch (Throwable e) {
     try {
       PrintStream f =
           new PrintStream(new FileOutputStream("c:\\Users\\7\\redline-smalltalk\\x2.txt"));
       e.printStackTrace(f);
     } catch (FileNotFoundException h) {
       throw new RuntimeException(h);
     }
     throw new RuntimeException("in variableAtShouldCallResolveObject");
   }
 }
    @Test
    public void testPostProcessHttpException() {
      HttpServletRequest request = mock(HttpServletRequest.class);
      HttpServletResponse response = mock(HttpServletResponse.class);
      RequestContext.getCurrentContext().setRequest(request);
      RequestContext.getCurrentContext().setResponse(response);

      FilterProcessor processor = new FilterProcessor();
      processor = spy(processor);
      try {
        when(processor.runFilters("post")).thenThrow(new ZuulException("test", 400, "test"));
        when(filter.filterType()).thenReturn("post");
        processor.postRoute();
      } catch (ZuulException e) {
        assertEquals(e.getMessage(), "test");
        assertEquals(e.nStatusCode, 400);
      } catch (Throwable e) {
        e.printStackTrace();
        assertFalse(true);
      }
    }