@Override @CheckReturnValue public SELF describedAs(Description description) { return super.describedAs(description); }
@Override @CheckReturnValue public SELF describedAs(String description, Object... args) { return super.describedAs(description, args); }
@Override @CheckReturnValue public SELF describedAs(String description, Object... args) { return super.describedAs(description, args); }
@Override @CheckReturnValue public SELF describedAs(Description description) { return super.describedAs(description); }
@Test public void testInvokeToString() throws Throwable { final Method toStringMethod = testService.getClass().getMethod("toString"); final Object result = testSubject.invoke(testService, toStringMethod, new Object[0]); verify(methodHandler, times(0)).invoke(any()); assertThat(feignDecorator.isCalled()) .describedAs("FeignDecorator is called") .isTrue(); assertThat(result) .describedAs("Return of invocation") .isEqualTo(target.toString()); }
@Test public void testInvoke() throws Throwable { final Object result = testSubject.invoke(testService, greetingMethod, new Object[0]); verify(methodHandler, times(1)).invoke(any()); assertThat(feignDecorator.isCalled()) .describedAs("FeignDecorator is called") .isTrue(); assertThat(result) .describedAs("Return of invocation") .isEqualTo(testService.greeting()); }
@Test public void testDecorator() throws Throwable { feignDecorator.setAlternativeFunction(fnArgs -> "AlternativeFunction"); testSubject = new DecoratorInvocationHandler(target, dispatch, feignDecorator); final Object result = testSubject.invoke(testService, greetingMethod, new Object[0]); verify(methodHandler, times(0)).invoke(any()); assertThat(feignDecorator.isCalled()) .describedAs("FeignDecorator is called") .isTrue(); assertThat(result) .describedAs("Return of invocation") .isEqualTo("AlternativeFunction"); }
@Test public void testWithRateLimiter() throws Throwable { final RateLimiter rateLimiter = spy(RateLimiter.ofDefaults("test")); final FeignDecorators testSubject = FeignDecorators.builder().withRateLimiter(rateLimiter).build(); final Object result = testSubject.decorate(args -> args[0], null, null, null).apply(new Object[] {"test01"}); assertThat(result) .describedAs("Returned result is correct") .isEqualTo("test01"); verify(rateLimiter, times(1)).getPermission(any()); } }
@Test public void testWithNothing() throws Throwable { final FeignDecorators testSubject = FeignDecorators.builder().build(); final Object result = testSubject.decorate(args -> args[0], null, null, null).apply(new Object[] {"test01"}); assertThat(result) .describedAs("Returned result is correct") .isEqualTo("test01"); }
@Test public void testWithCircuitBreaker() throws Throwable { final CircuitBreaker circuitBreaker = CircuitBreaker.ofDefaults("test"); final CircuitBreaker.Metrics metrics = circuitBreaker.getMetrics(); final FeignDecorators testSubject = FeignDecorators.builder().withCircuitBreaker(circuitBreaker).build(); final Object result = testSubject.decorate(args -> args[0], null, null, null).apply(new Object[] {"test01"}); assertThat(result) .describedAs("Returned result is correct") .isEqualTo("test01"); assertThat(metrics.getNumberOfSuccessfulCalls()) .describedAs("Successful Calls") .isEqualTo(1); }
protected Consumer<Change> matchChange(String path, Object value) { return change -> assertThat(change) .describedAs("change") .isNotNull() .satisfies(it -> assertThat(ChangesTestSubscriber.getPathString(it)).describedAs("path").isEqualTo(path)) .satisfies(it -> assertThat(it.getData()).describedAs("data").isEqualTo(value)); }
protected void assertDataProviderFrameworkMethods(List<FrameworkMethod> actuals, List<Object[]> expecteds, String expectedNameFormat) { assertThat(actuals).hasSameSizeAs(expecteds); for (int idx = 0; idx < actuals.size(); idx++) { assertThat(actuals.get(idx)).describedAs("at idx " + idx).isInstanceOf(DataProviderFrameworkMethod.class); DataProviderFrameworkMethod actual = (DataProviderFrameworkMethod) actuals.get(idx); assertThat(actual.idx).describedAs("at idx " + idx).isEqualTo(idx); assertThat(actual.parameters).describedAs("at idx " + idx).isEqualTo(expecteds.get(idx)); assertThat(actual.nameFormat).describedAs("at idx " + idx).isEqualTo(expectedNameFormat); } }
public void testExecutor() throws Exception { final CountDownLatch sync = new CountDownLatch(1); Runnable task = new Runnable() { @Override public void run() { sync.countDown(); } }; goro.getExecutor("test").execute(task); assertThat(sync.await(2, TimeUnit.SECONDS)).describedAs("Operation timed out").isTrue(); waitMainThread(); assertThat(goro.delegate()).describedAs("Service must be unbound").isNull(); }
@Test public void deserializeIncompleteMessage() throws Exception { final MessageSubscriptionPayload<Category> messageSubscriptionPayload = SphereJsonUtils.readObjectFromResource("MessageSubscriptionIncompletePayload.json", MessageSubscriptionPayload.class); assertThat(messageSubscriptionPayload).isNotNull(); assertThat(messageSubscriptionPayload.hasCompleteMessage()).isFalse(); final Message message = messageSubscriptionPayload.getMessage(); assertThat(message) .describedAs("Partial message is available").isNotNull(); assertThat(message.getType()).isNull(); assertThatThrownBy(() -> messageSubscriptionPayload.as(CategoryCreatedMessage.class)).isInstanceOf(IllegalStateException.class); } }
/** * Asserts that the given flow has a step at the given index of the given type */ public static <T extends Step> T assertFlowHasStep(Flow flow, int index, Class<T> clazz) { List<Step> steps = flow.getSteps(); String stepsMessage = "flow " + flow + " steps"; assertThat(steps).describedAs(stepsMessage).isNotEmpty(); int size = steps.size(); assertThat(size).describedAs(stepsMessage + " size").isGreaterThan(index); Step step = steps.get(index); String stepMessage = "flow " + flow + " step " + index + " " + step; assertThat(step).describedAs(stepMessage).isInstanceOf(clazz); return clazz.cast(step); } }
public void testSchedule() throws InterruptedException { final CountDownLatch sync = new CountDownLatch(1); Callable<String> task = new Callable<String>() { @Override public String call() { return "done"; } }; final Object[] result = new Object[1]; goro.schedule(task) .subscribe(new FutureObserver<String>() { @Override public void onSuccess(final String value) { result[0] = value; sync.countDown(); } @Override public void onError(final Throwable error) { result[0] = error; sync.countDown(); } }); assertThat(sync.await(2, TimeUnit.SECONDS)).describedAs("Operation timed out").isTrue(); assertThat(result).containsOnly("done"); waitMainThread(); assertThat(goro.delegate()).describedAs("Service must be unbound").isNull(); }