|
| 1 | +package com.netflix.hystrix.contrib.javanica.command; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.junit.runners.Parameterized; |
| 6 | +import rx.Observable; |
| 7 | +import rx.internal.operators.OperatorMulticast; |
| 8 | + |
| 9 | +import java.util.List; |
| 10 | +import java.util.concurrent.CompletableFuture; |
| 11 | +import java.util.concurrent.Future; |
| 12 | +import java.util.concurrent.RunnableFuture; |
| 13 | + |
| 14 | +import static com.netflix.hystrix.contrib.javanica.command.ExecutionType.ASYNCHRONOUS; |
| 15 | +import static com.netflix.hystrix.contrib.javanica.command.ExecutionType.OBSERVABLE; |
| 16 | +import static com.netflix.hystrix.contrib.javanica.command.ExecutionType.SYNCHRONOUS; |
| 17 | +import static java.util.Arrays.asList; |
| 18 | +import static org.junit.Assert.assertEquals; |
| 19 | + |
| 20 | +@RunWith(Parameterized.class) |
| 21 | +public class ExecutionTypeTest { |
| 22 | + |
| 23 | + @Parameterized.Parameters |
| 24 | + public static List<Object[]> data() { |
| 25 | + return asList(new Object[][]{ |
| 26 | + {returnType(Integer.class), shouldHaveExecutionType(SYNCHRONOUS)}, |
| 27 | + {returnType(List.class), shouldHaveExecutionType(SYNCHRONOUS)}, |
| 28 | + {returnType(Object.class), shouldHaveExecutionType(SYNCHRONOUS)}, |
| 29 | + {returnType(Class.class), shouldHaveExecutionType(SYNCHRONOUS)}, |
| 30 | + {returnType(Future.class), shouldHaveExecutionType(ASYNCHRONOUS)}, |
| 31 | + {returnType(AsyncResult.class), shouldHaveExecutionType(ASYNCHRONOUS)}, |
| 32 | + {returnType(RunnableFuture.class), shouldHaveExecutionType(ASYNCHRONOUS)}, |
| 33 | + {returnType(CompletableFuture.class), shouldHaveExecutionType(ASYNCHRONOUS)}, |
| 34 | + {returnType(Observable.class), shouldHaveExecutionType(OBSERVABLE)}, |
| 35 | + {returnType(OperatorMulticast.class), shouldHaveExecutionType(OBSERVABLE)}, |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void should_return_correct_execution_type() throws Exception { |
| 41 | + assertEquals("Unexpected execution type for method return type: " + methodReturnType, expectedType, ExecutionType.getExecutionType(methodReturnType)); |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + private static ExecutionType shouldHaveExecutionType(final ExecutionType type) { |
| 46 | + return type; |
| 47 | + } |
| 48 | + |
| 49 | + private static Class<?> returnType(final Class<?> aClass) { |
| 50 | + return aClass; |
| 51 | + } |
| 52 | + |
| 53 | + private final Class<?> methodReturnType; |
| 54 | + private final ExecutionType expectedType; |
| 55 | + |
| 56 | + public ExecutionTypeTest(final Class<?> methodReturnType, final ExecutionType expectedType) { |
| 57 | + this.methodReturnType = methodReturnType; |
| 58 | + this.expectedType = expectedType; |
| 59 | + } |
| 60 | +} |
0 commit comments