Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzzle committed Aug 2, 2016
1 parent 38f8a7f commit 5f709ab
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package de.skuzzle.inject.async.internal.runnables;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class LatchLockableRunnableTest {

@Mock
private Runnable runnable;
@InjectMocks
private LatchLockableRunnable subject;

@Test(timeout = 5000)
public void testRunAfterRelease() throws Exception {
final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(this.subject);
Thread.sleep(250);
verify(this.runnable, never()).run();
this.subject.release();

Thread.sleep(250);
verify(this.runnable).run();
}

@Test(timeout = 5000)
public void testRunInterrupt() throws Exception {
final ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(this.subject);

Thread.sleep(250);
executor.shutdownNow();
verify(this.runnable, never()).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public void testCreateRunnableStack() throws Throwable {
order.verify(this.context).finishExecution();
}

@Test
public void testCreateLockedRunnable() throws Throwable {
final LockableRunnable runnable = this.subject.createLockedRunnableStack(
this.invocation, this.context, this.handler);

runnable.release();
runnable.run();

final InOrder order = inOrder(this.invocation, this.context, this.handler);
order.verify(this.context).beginNewExecution();
order.verify(this.invocation).proceed();
order.verify(this.context).finishExecution();
}

@Test
public void testCreateRunnableStackException() throws Throwable {
final RuntimeException ex = new RuntimeException();
Expand All @@ -55,4 +69,5 @@ public void testCreateRunnableStackException() throws Throwable {
order.verify(this.handler).onException(ex);
order.verify(this.context).finishExecution();
}

}

0 comments on commit 5f709ab

Please sign in to comment.