use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MenuViewTest method testStoreChanged.
@Test
public void testStoreChanged() throws Exception {
final MenuStore store = mock(MenuStore.class);
when(store.getSelected()).thenReturn(MenuItem.HOME);
final MenuView view = new MenuView();
view.storeChanged(store);
verify(store, times(1)).getSelected();
verifyNoMoreInteractions(store);
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MenuViewTest method testItemClicked.
@Test
public void testItemClicked() throws Exception {
final Store store = mock(Store.class);
Dispatcher.getInstance().registerStore(store);
final MenuView view = new MenuView();
view.itemClicked(MenuItem.PRODUCTS);
// We should receive a menu click action and a content changed action
verify(store, times(2)).onAction(any(Action.class));
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class AsynchronousServiceTest method testPerfectExecution.
@Test
public void testPerfectExecution() throws Exception {
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
final AsyncTask<Object> task = mock(AsyncTask.class);
final Object result = new Object();
when(task.call()).thenReturn(result);
service.execute(task);
verify(task, timeout(2000)).onPostCall(eq(result));
final InOrder inOrder = inOrder(task);
inOrder.verify(task, times(1)).onPreCall();
inOrder.verify(task, times(1)).call();
inOrder.verify(task, times(1)).onPostCall(eq(result));
verifyNoMoreInteractions(task);
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MongoEventLogTest method testFundTransfers.
@Test
public void testFundTransfers() {
PlayerDetails playerDetails = new PlayerDetails("john@wayne.com", "000-000", "03432534543");
mongoEventLog.prizeError(playerDetails, 1000);
assertEquals(1, mongoEventLog.getEventsCollection().count());
mongoEventLog.prizeError(playerDetails, 1000);
assertEquals(2, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketDidNotWin(playerDetails);
assertEquals(3, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketDidNotWin(playerDetails);
assertEquals(4, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketSubmitError(playerDetails);
assertEquals(5, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketSubmitError(playerDetails);
assertEquals(6, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketSubmitted(playerDetails);
assertEquals(7, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketSubmitted(playerDetails);
assertEquals(8, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketWon(playerDetails, 1000);
assertEquals(9, mongoEventLog.getEventsCollection().count());
mongoEventLog.ticketWon(playerDetails, 1000);
assertEquals(10, mongoEventLog.getEventsCollection().count());
}
use of org.junit.jupiter.api.Test in project java-design-patterns by iluwatar.
the class MuteTest method loggedMuteShouldLogExceptionTraceBeforeSwallowingIt.
@Test
public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
System.setErr(new PrintStream(stream));
Mute.loggedMute(() -> methodThrowingException());
assertTrue(new String(stream.toByteArray()).contains(MESSAGE));
}
Aggregations