DefaultThreadManager extends HaloThreadManager { @Override public Future enqueue(@Threading.Policy int thread, @NonNull Runnable runnable) { Future<?> future; switch (thread) { case Threading.POOL_QUEUE_POLICY: future = mPoolQueue.submit(runnable); break; case Threading.SINGLE_QUEUE_POLICY: future = mSingleQueue.submit(runnable); break; case Threading.SAME_THREAD_POLICY: future = new FutureTask<>(runnable, null); runnable.run(); break; default: throw new HaloConfigurationException("Unsupported option or an Action operation"); } return future; } DefaultThreadManager(); @Override Future enqueue(@Threading.Policy int thread, @NonNull Runnable runnable);  }
@Test public void thatCanCreateADefaultThreadManagerWithPoolQueuePolicy() { DefaultThreadManager defaultThreadManager = new DefaultThreadManager(); Future future = defaultThreadManager.enqueue(Threading.POOL_QUEUE_POLICY, givenARunnable(mCallbackFlag)); assertThat(mCallbackFlag.isFlagged()).isFalse(); assertThat(future).isNotNull(); }
@Test public void thatCanCreateADefaultThreadManagerWithSingleQueuePolicy() { DefaultThreadManager defaultThreadManager = new DefaultThreadManager(); Future future = defaultThreadManager.enqueue(Threading.SINGLE_QUEUE_POLICY, givenARunnable(mCallbackFlag)); assertThat(mCallbackFlag.isFlagged()).isFalse(); assertThat(future).isNotNull(); }
@Test public void thatCanCreateADefaultThreadManagerWithSameThreadQueuePolicy() { DefaultThreadManager defaultThreadManager = new DefaultThreadManager(); Future future = defaultThreadManager.enqueue(Threading.SAME_THREAD_POLICY, givenARunnable(mCallbackFlag)); assertThat(mCallbackFlag.isFlagged()).isFalse(); assertThat(future).isNotNull(); }
@Test public void thatCanCreateADefaultThreadManagerAndThrowAHaloConfigurationException() { DefaultThreadManager defaultThreadManager = new DefaultThreadManager(); try { Future future = defaultThreadManager.enqueue(5, givenARunnable(mCallbackFlag)); }catch(HaloConfigurationException haloConfigurationException){ assertThat(haloConfigurationException.getMessage()).contains("Unsupported"); } }