/** * Creates a new instance of {@code CallableBackgroundInitializer} and sets * the {@code Callable} to be executed in a background thread. * * @param call the {@code Callable} (must not be <b>null</b>) * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call) { checkCallable(call); callable = call; }
/** * Tries to pass a null Callable to the constructor that takes an executor. * This should cause an exception. */ @Test(expected=IllegalArgumentException.class) public void testInitExecutorNullCallable() throws InterruptedException { final ExecutorService exec = Executors.newSingleThreadExecutor(); try { new CallableBackgroundInitializer<Integer>(null, exec); } finally { exec.shutdown(); exec.awaitTermination(1, TimeUnit.SECONDS); } }
/** * Tests whether the executor service is correctly passed to the super * class. */ @Test public void testInitExecutor() throws InterruptedException { final ExecutorService exec = Executors.newSingleThreadExecutor(); final CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<>( new TestCallable(), exec); assertEquals("Executor not set", exec, init.getExternalExecutor()); exec.shutdown(); exec.awaitTermination(1, TimeUnit.SECONDS); }
/** * Tests the implementation of initialize(). * * @throws java.lang.Exception so we don't have to catch it */ @Test public void testInitialize() throws Exception { final TestCallable call = new TestCallable(); final CallableBackgroundInitializer<Integer> init = new CallableBackgroundInitializer<>( call); assertEquals("Wrong result", RESULT, init.initialize()); assertEquals("Wrong number of invocations", 1, call.callCount); }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and * initializes it with the {@code Callable} to be executed in a background * thread and the {@code ExecutorService} for managing the background * execution. * * @param call the {@code Callable} (must not be <b>null</b>) * @param exec an external {@code ExecutorService} to be used for task * execution * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call, final ExecutorService exec) { super(exec); checkCallable(call); callable = call; }
/** * Tries to create an instance without a Callable. This should cause an * exception. */ @Test(expected=IllegalArgumentException.class) public void testInitNullCallable() { new CallableBackgroundInitializer<>(null); }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and sets * the {@code Callable} to be executed in a background thread. * * @param call the {@code Callable} (must not be <b>null</b>) * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call) { checkCallable(call); callable = call; }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and sets * the {@code Callable} to be executed in a background thread. * * @param call the {@code Callable} (must not be <b>null</b>) * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call) { checkCallable(call); callable = call; }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and sets * the {@code Callable} to be executed in a background thread. * * @param call the {@code Callable} (must not be <b>null</b>) * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call) { checkCallable(call); callable = call; }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and * initializes it with the {@code Callable} to be executed in a background * thread and the {@code ExecutorService} for managing the background * execution. * * @param call the {@code Callable} (must not be <b>null</b>) * @param exec an external {@code ExecutorService} to be used for task * execution * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call, final ExecutorService exec) { super(exec); checkCallable(call); callable = call; }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and * initializes it with the {@code Callable} to be executed in a background * thread and the {@code ExecutorService} for managing the background * execution. * * @param call the {@code Callable} (must not be <b>null</b>) * @param exec an external {@code ExecutorService} to be used for task * execution * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call, final ExecutorService exec) { super(exec); checkCallable(call); callable = call; }
/** * Creates a new instance of {@code CallableBackgroundInitializer} and * initializes it with the {@code Callable} to be executed in a background * thread and the {@code ExecutorService} for managing the background * execution. * * @param call the {@code Callable} (must not be <b>null</b>) * @param exec an external {@code ExecutorService} to be used for task * execution * @throws IllegalArgumentException if the {@code Callable} is <b>null</b> */ public CallableBackgroundInitializer(final Callable<T> call, final ExecutorService exec) { super(exec); checkCallable(call); callable = call; }