@Test public void shouldFindBorrowableBook() throws NoBookBorrowableException { when(emMock.createNamedQuery("findBorrowableBookByISBN")).thenReturn(queryMock); when(queryMock.setParameter(Mockito.isA(String.class), Mockito.isA(String.class))) .thenReturn(queryMock); when(queryMock.setMaxResults(Mockito.isA(Integer.class))).thenReturn(queryMock); when(queryMock.getSingleResult()).thenReturn(validAvailableBook); Book book = bookRepository.findBorrowableBook("1234"); verify(queryMock).setParameter("isbn", "1234"); assertNotNull(book); }
@Test public void shouldFindAllBorrowBooksByEmail() { List<Book> result = new ArrayList<Book>(); result.add(validAvailableBook); when(emMock.createNamedQuery("findAllBorrowedBooksByEmail")).thenReturn(queryMock); when(queryMock.setParameter(Mockito.isA(String.class), Mockito.isA(String.class))) .thenReturn(queryMock); when(queryMock.getResultList()).thenReturn(result); List<Book> books = bookRepository.findAllBorrowedBooksByBorrower("*****@*****.**"); assertEquals(1, books.size()); }
@Test public void shouldNotFindAnyBorrowableBook() { when(emMock.createNamedQuery("findBorrowableBookByISBN")).thenReturn(queryMock); when(queryMock.setParameter(Mockito.isA(String.class), Mockito.isA(String.class))) .thenReturn(queryMock); when(queryMock.setMaxResults(Mockito.isA(Integer.class))).thenReturn(queryMock); when(queryMock.getSingleResult()).thenThrow(new NoResultException()); try { bookRepository.findBorrowableBook("1234"); fail("exception expected"); } catch (NoBookBorrowableException e) { assertThat(e.getIsbn(), is("1234")); } }
private void setupMedia() throws Exception { final Attachment attachment = Attachment.create().name("logo.png").mimeType("image/png").label("small").build(); final Media content = createMedia("123456", "path/to/content", attachment); Mockito.when(this.contentService.getById(Mockito.eq(content.getId()))).thenReturn(content); Mockito.when(this.contentService.getByPath(Mockito.eq(content.getPath()))).thenReturn(content); this.mediaBytes = ByteSource.wrap(new byte[0]); Mockito.when( this.contentService.getBinary( Mockito.isA(ContentId.class), Mockito.isA(BinaryReference.class))) .thenReturn(this.mediaBytes); }
@Test public void testCreateJob() throws Exception { SalesforceConnector connector = new SalesforceConnector(); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); connector.setBulkConnection(bulkConnection); ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class); Mockito.when(bulkConnection.createJob(Mockito.isA(JobInfo.class))) .thenAnswer( new Answer<JobInfo>() { @Override public JobInfo answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); return (JobInfo) args[0]; } }); JobInfo actualJobInfo = connector.createJob(OperationEnum.upsert, "Account", "NewField", ContentType.CSV, null); Mockito.verify(bulkConnection).createJob(expectedJobInfo.capture()); assertEquals(expectedJobInfo.getValue(), actualJobInfo); assertEquals(OperationEnum.upsert, expectedJobInfo.getValue().getOperation()); assertEquals(actualJobInfo.getObject(), expectedJobInfo.getValue().getObject()); assertEquals( actualJobInfo.getExternalIdFieldName(), expectedJobInfo.getValue().getExternalIdFieldName()); assertEquals(actualJobInfo.getContentType(), expectedJobInfo.getValue().getContentType()); }
protected final void setupTemplates() throws Exception { Mockito.when(this.pageTemplateService.getByKey(Mockito.eq(PageTemplateKey.from("my-page")))) .thenReturn(createPageTemplate()); Mockito.when(this.pageDescriptorService.getByKey(Mockito.isA(DescriptorKey.class))) .thenReturn(createDescriptor()); }
@Test public final void test_get_mixin() throws Exception { Mixin mixin = Mixin.create() .createdTime(LocalDateTime.of(2013, 1, 1, 12, 0, 0).toInstant(ZoneOffset.UTC)) .name(MY_MIXIN_QUALIFIED_NAME_1.toString()) .addFormItem( Input.create() .name(MY_MIXIN_INPUT_NAME_1) .inputType(InputTypeName.TEXT_LINE) .label("Line Text 1") .required(true) .helpText("Help text line 1") .required(true) .build()) .build(); Mockito.when(mixinService.getByName(Mockito.isA(MixinName.class))).thenReturn(mixin); String response = request() .path("schema/mixin") .queryParam("name", MY_MIXIN_QUALIFIED_NAME_1.toString()) .get() .getAsString(); assertJson("get_mixin.json", response); }
@Test public void shouldSelectAllBooks() { List<Book> result = new ArrayList<Book>(); result.add(validAvailableBook); when(emMock.createNamedQuery("findAllBooks")).thenReturn(queryMock); when(queryMock.setParameter(Mockito.isA(String.class), Mockito.isA(String.class))) .thenReturn(queryMock); when(queryMock.getResultList()).thenReturn(result); List<Book> books = bookRepository.findAllBooks(); verify(emMock).createNamedQuery("findAllBooks"); assertEquals(1, books.size()); }
@Test public void VerifyActivatorInit() throws Exception { m_activator.init(m_context, m_manager); Mockito.verify(m_manager).add(Mockito.isA(Service.class)); }
protected final void setupNonPageContent() throws Exception { Mockito.when( this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())) .thenReturn(createPage("id", "site/somepath/content", "myapplication:ctype", false)); Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class))) .thenReturn(createSite("id", "site", "myapplication:contenttypename")); }
/** * Set up the test environment. * * @since 0.7.6 */ @Before public void setUp() { final SsmlParsingStrategyFactory factory = Mockito.mock(SsmlParsingStrategyFactory.class); Mockito.when(factory.getParsingStrategy(Mockito.isA(Value.class))) .thenReturn(new ValueStrategy()); final VoiceXmlInterpreterContext context = getContext(); final Profile profile = context.getProfile(); Mockito.when(profile.getSsmlParsingStrategyFactory()).thenReturn(factory); Mockito.when(profile.getSsmlParsingStrategyFactory()).thenReturn(factory); final TagStrategyFactory tagfactory = Mockito.mock(TagStrategyFactory.class); Mockito.when(tagfactory.getTagStrategy(Mockito.isA(Value.class))) .thenReturn(new ValueStrategy()); Mockito.when(tagfactory.getTagStrategy(Mockito.isA(Text.class))).thenReturn(new TextStrategy()); Mockito.when(profile.getTagStrategyFactory()).thenReturn(tagfactory); final ImplementationPlatform platform = Mockito.mock(ImplementationPlatform.class); Mockito.when(context.getImplementationPlatform()).thenReturn(platform); }
@Test(expected = ConnectionException.class) public void testCreateBatchForQueryWithConnectionException() throws Exception { SalesforceConnector connector = new SalesforceConnector(); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class); AsyncApiException exception = Mockito.mock(AsyncApiException.class); connector.setBulkConnection(bulkConnection); JobInfo actualJobInfo = new JobInfo(); String query = "SELECT Id FROM Contact"; Mockito.when(exception.getExceptionCode()).thenReturn(AsyncExceptionCode.InvalidSessionId); Mockito.when( bulkConnection.createBatchFromStream( expectedJobInfo.capture(), Mockito.isA(InputStream.class))) .thenThrow(exception); connector.createBatchForQuery(actualJobInfo, query); assertEquals(expectedJobInfo.getValue(), actualJobInfo); }
protected final void setupCustomizedTemplateContentAndSite() throws Exception { Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true); final PageDescriptor controllerDescriptor = createDescriptor(); Page page = Page.create(content.getPage()) .template(null) .controller(controllerDescriptor.getKey()) .build(); content = Content.create(content).page(page).build(); Mockito.when( this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())) .thenReturn(content); Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class))) .thenReturn(createSite("id", "site", "myapplication:contenttypename")); Mockito.when(this.contentService.getById(content.getId())).thenReturn(content); }
@Test public void testCreateBatchStream() throws Exception { SalesforceConnector connector = new SalesforceConnector(); BulkConnection bulkConnection = Mockito.mock(BulkConnection.class); ArgumentCaptor<JobInfo> expectedJobInfo = ArgumentCaptor.forClass(JobInfo.class); connector.setBulkConnection(bulkConnection); JobInfo actualJobInfo = new JobInfo(); InputStream stream = Mockito.mock(InputStream.class); BatchInfo expectedBatchInfo = new BatchInfo(); Mockito.when( bulkConnection.createBatchFromStream( expectedJobInfo.capture(), Mockito.isA(InputStream.class))) .thenReturn(expectedBatchInfo); BatchInfo actualBatchInfo = connector.createBatchStream(actualJobInfo, stream); assertEquals(expectedBatchInfo, actualBatchInfo); assertEquals(expectedJobInfo.getValue(), actualJobInfo); }
protected final void setupController() throws Exception { Mockito.when(this.pageDescriptorService.getByKey(Mockito.isA(DescriptorKey.class))) .thenReturn(createDescriptor()); }
@Before public void prepare() { MockitoAnnotations.initMocks(this); BDDMockito.given(modelService.create(Mockito.any(Class.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { final Class clazz = (Class) invocation.getArguments()[0]; return clazz.newInstance(); } }); BDDMockito.given(contentCatalog.getName()).willReturn("root_content_catalog"); BDDMockito.given(modelService.clone(Mockito.isA(ContentSlotForTemplateModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return slotTemplateClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(PageTemplateModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return pageTemplateClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(SimpleCMSComponentModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return componentClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(ContentSlotModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return contentSlotClone; } }); }
@Before public void setUp() throws com.yazino.game.api.GameException, WalletServiceException { MockitoAnnotations.initMocks(this); timeSource = new SettableTimeSource(System.currentTimeMillis()); command = new CommandWrapper(TABLE_ID, GAME_ID, A_PLAYER.getId(), SESSION_ID, "T"); command.setRequestId(UUID); playerStatisticEventsPublisher = new InMemoryPlayerStatisticEventsPublisher(); table = new Table( new com.yazino.game.api.GameType(GAME_TYPE, "Test", Collections.<String>emptySet()), BigDecimal.ONE, "test", true); table.setTableId(TABLE_ID); table.setTableStatus(TableStatus.open); table.setVariationProperties(new HashMap<String, String>()); when(bufferedGameHostWalletFactory.create(table.getTableId(), command.getRequestId())) .thenReturn(bufferedGameHostWallet); when(bufferedGameHostWalletFactory.create(table.getTableId())) .thenReturn(bufferedGameHostWallet); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(BigDecimal.ZERO); when(uuidSource.getNewUUID()).thenReturn(NEW_UUID); when(auditor.newLabel()).thenReturn(AUDIT_LABEL); when(bufferedGameHostWallet.getBalance(Mockito.isA(BigDecimal.class))) .thenReturn(ACCOUNT_BALANCE); when(gameRules.getGameType()).thenReturn("TEST"); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, SESSION_ID)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER_ID, null)) .thenReturn( aPlayerSessionSummary(PLAYER_ID, "Player", PLAYER_ACCOUNT_ID, BigDecimal.valueOf(100))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER1_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER1_ID, "Player1", PLAYER1_ACCOUNT_ID, BigDecimal.valueOf(200))); when(playerRepository.findSummaryByPlayerAndSession(PLAYER2_ID, null)) .thenReturn( aPlayerSessionSummary( PLAYER2_ID, "Player2", PLAYER2_ACCOUNT_ID, BigDecimal.valueOf(300))); when(chatRepository.getOrCreateForLocation(TABLE_ID.toPlainString())) .thenReturn(new ChatChannel(TABLE_ID.toPlainString())); }