private byte[] dropDeletesMatcher(Boolean dropDeletes, byte[] value) { return dropDeletes == null ? any() : (dropDeletes.booleanValue() ? aryEq(value) : isNull(byte[].class)); }
private void setupContactProviderForId(String id, String[]... contacts) { MatrixCursor cursor = new MatrixCursor(PROJECTION); for (String[] contact : contacts) { cursor.addRow(contact); } when(contentResolver .query(eq(Email.CONTENT_URI), aryEq(PROJECTION), nullable(String.class), aryEq(new String[] { id }), nullable(String.class))).thenReturn(cursor); }
private void setupContactProvider(String queriedAddress, String[]... contacts) { MatrixCursor cursor = new MatrixCursor(PROJECTION); for (String[] contact : contacts) { cursor.addRow(contact); } when(contentResolver .query(eq(Email.CONTENT_URI), aryEq(PROJECTION), nullable(String.class), aryEq(new String[] { queriedAddress, queriedAddress }), nullable(String.class))).thenReturn(cursor); }
@Test public void findOneChildren() { List<ObjectIdentity> result = new ArrayList<>(); result.add(new ObjectIdentityImpl(Object.class, "5577")); Object[] args = {"1", "org.springframework.security.acls.jdbc.JdbcAclServiceTests$MockLongIdDomainObject"}; when( jdbcOperations.query(anyString(), aryEq(args), any(RowMapper.class))).thenReturn(result); ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockLongIdDomainObject.class, 1L); List<ObjectIdentity> objectIdentities = aclService.findChildren(objectIdentity); assertThat(objectIdentities.size()).isEqualTo(1); assertThat(objectIdentities.get(0).getIdentifier()).isEqualTo("5577"); }
private void setupQueryCryptoProvider(String queriedAddress, Address... contactAddresses) { MatrixCursor cursor = new MatrixCursor(PROJECTION_CRYPTO_ADDRESSES); for (Address contactAddress : contactAddresses) { cursor.addRow(new String[] { queriedAddress, contactAddress.toString() }); } when(contentResolver .query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")), aryEq(PROJECTION_CRYPTO_ADDRESSES), nullable(String.class), aryEq(new String[] { queriedAddress }), nullable(String.class))).thenReturn(cursor); }
private void setupCryptoProviderStatus(Address address, String uidStatus, String autocryptStatus) { MatrixCursor cursorCryptoStatus = new MatrixCursor(PROJECTION_CRYPTO_STATUS); cursorCryptoStatus.addRow(new String[] { address.getAddress(), uidStatus, autocryptStatus }); when(contentResolver .query(eq(Uri.parse("content://" + CRYPTO_PROVIDER + ".provider.exported/autocrypt_status")), aryEq(PROJECTION_CRYPTO_STATUS), nullable(String.class), aryEq(new String[] { address.getAddress() }), nullable(String.class))).thenReturn(cursorCryptoStatus); }
@Test public void testSend() throws Exception { MimeMessage foo = new MimeMessage(session); MimeMessage bar = new MimeMessage(session); MimeMessage[] items = new MimeMessage[] { foo, bar }; mailSender.send(aryEq(items)); writer.write(Arrays.asList(items)); }
private void setupNicknameContactProvider(String[]... contactsWithNickname) { MatrixCursor cursor = new MatrixCursor(PROJECTION_NICKNAME); for (String[] contact : contactsWithNickname) { cursor.addRow(contact); } when(contentResolver .query(eq(ContactsContract.Data.CONTENT_URI), aryEq(PROJECTION_NICKNAME), nullable(String.class), nullable(String[].class), nullable(String.class))).thenReturn(cursor); }
private void setupContactProvider(String[]... contacts) { MatrixCursor cursor = new MatrixCursor(PROJECTION); for (String[] contact : contacts) { cursor.addRow(contact); } when(contentResolver .query(eq(Email.CONTENT_URI), aryEq(PROJECTION), isNull(String.class), isNull(String[].class), nullable(String.class))).thenReturn(cursor); } }
@Test(expected = MailSendException.class) public void testDefaultErrorHandler() throws Exception { MimeMessage foo = new MimeMessage(session); MimeMessage bar = new MimeMessage(session); MimeMessage[] items = new MimeMessage[] { foo, bar }; // Spring 4.1 changed the send method to be vargs instead of an array if(ReflectionUtils.findMethod(MailSender.class, "send", MimeMessage[].class) != null) { mailSender.send(aryEq(items)); } else { mailSender.send(items); } when(mailSender).thenThrow(new MailSendException(Collections.singletonMap((Object)foo, (Exception)new MessagingException("FOO")))); writer.write(Arrays.asList(items)); }
@Test public void testSend() throws Exception { SimpleMailMessage foo = new SimpleMailMessage(); SimpleMailMessage bar = new SimpleMailMessage(); SimpleMailMessage[] items = new SimpleMailMessage[] { foo, bar }; writer.write(Arrays.asList(items)); // Spring 4.1 changed the send method to be vargs instead of an array if(ReflectionUtils.findMethod(SimpleMailMessage.class, "send", SimpleMailMessage[].class) != null) { verify(mailSender).send(aryEq(items)); } else { verify(mailSender).send(items); } }
@Test public void testWithReferences() throws Exception { StripeCompactionPolicy policy = createPolicy(HBaseConfiguration.create()); StripeCompactor sc = mock(StripeCompactor.class); HStoreFile ref = createFile(); when(ref.isReference()).thenReturn(true); StripeInformationProvider si = mock(StripeInformationProvider.class); Collection<HStoreFile> sfs = al(ref, createFile()); when(si.getStorefiles()).thenReturn(sfs); assertTrue(policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); // UnmodifiableCollection does not implement equals so we need to change it here to a // collection that implements it. assertEquals(si.getStorefiles(), new ArrayList<>(scr.getRequest().getFiles())); scr.execute(sc, NoLimitThroughputController.INSTANCE, null); verify(sc, only()).compact(eq(scr.getRequest()), anyInt(), anyLong(), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), aryEq(OPEN_KEY), any(), any()); }
when( message.getMatchingHeaders( AdditionalMatchers.aryEq( new String[] { HDR_EX1 } ) ) ).thenReturn( getEnum( new Header[] { ex1 } ) ); when( message.getMatchingHeaders( AdditionalMatchers.aryEq( new String[] { HDR_EX2 } ) ) ).thenReturn( getEnum( new Header[] { ex2 } ) ); when( message.getMatchingHeaders( AdditionalMatchers.aryEq( new String[] { HDR_EX1, HDR_EX2 } ) ) ).thenReturn( getEnum( new Header[] { ex1, ex2 } ) );
/** * Verify arbitrary compaction. * @param policy Policy to test. * @param si Stripe information pre-set with stripes to test. * @param sfs Files that should be compacted. * @param dropDeletes Whether to drop deletes from compaction range. * @param count Expected # of resulting stripes, null if not checked. * @param size Expected target stripe size, null if not checked. * @param start Left boundary of the compaction. * @param end Right boundary of the compaction. */ private void verifyCompaction(StripeCompactionPolicy policy, StripeInformationProvider si, Collection<HStoreFile> sfs, Boolean dropDeletes, Integer count, Long size, byte[] start, byte[] end, boolean needsCompaction) throws IOException { StripeCompactor sc = mock(StripeCompactor.class); assertTrue(!needsCompaction || policy.needsCompactions(si, al())); StripeCompactionPolicy.StripeCompactionRequest scr = policy.selectCompaction(si, al(), false); verifyCollectionsEqual(sfs, scr.getRequest().getFiles()); scr.execute(sc, NoLimitThroughputController.INSTANCE, null); verify(sc, times(1)).compact(eq(scr.getRequest()), count == null ? anyInt() : eq(count.intValue()), size == null ? anyLong() : eq(size.longValue()), aryEq(start), aryEq(end), dropDeletesMatcher(dropDeletes, start), dropDeletesMatcher(dropDeletes, end), any(), any()); }
@Test public void testCustomErrorHandler() throws Exception { final AtomicReference<String> content = new AtomicReference<>(); writer.setMailErrorHandler(new MailErrorHandler() { @Override public void handle(MailMessage message, Exception exception) throws MailException { content.set(exception.getMessage()); } }); MimeMessage foo = new MimeMessage(session); MimeMessage bar = new MimeMessage(session); MimeMessage[] items = new MimeMessage[] { foo, bar }; // Spring 4.1 changed the send method to be vargs instead of an array if(ReflectionUtils.findMethod(MailSender.class, "send", MimeMessage[].class) != null) { mailSender.send(aryEq(items)); } else { mailSender.send(items); } when(mailSender).thenThrow(new MailSendException(Collections.singletonMap((Object)foo, (Exception)new MessagingException("FOO")))); writer.write(Arrays.asList(items)); assertEquals("FOO", content.get()); }
@Test(expected = MailSendException.class) public void testDefaultErrorHandler() throws Exception { SimpleMailMessage foo = new SimpleMailMessage(); SimpleMailMessage bar = new SimpleMailMessage(); SimpleMailMessage[] items = new SimpleMailMessage[] { foo, bar }; // Spring 4.1 changed the send method to be vargs instead of an array if(ReflectionUtils.findMethod(SimpleMailMessage.class, "send", SimpleMailMessage[].class) != null) { mailSender.send(aryEq(items)); } else { mailSender.send(items); } when(mailSender).thenThrow(new MailSendException(Collections.singletonMap((Object)foo, (Exception)new MessagingException("FOO")))); writer.write(Arrays.asList(items)); }
@Test public void testCustomErrorHandler() throws Exception { final AtomicReference<String> content = new AtomicReference<>(); writer.setMailErrorHandler(new MailErrorHandler() { @Override public void handle(MailMessage message, Exception exception) throws MailException { content.set(exception.getMessage()); } }); SimpleMailMessage foo = new SimpleMailMessage(); SimpleMailMessage bar = new SimpleMailMessage(); SimpleMailMessage[] items = new SimpleMailMessage[] { foo, bar }; // Spring 4.1 changed the send method to be vargs instead of an array if(ReflectionUtils.findMethod(SimpleMailMessage.class, "send", SimpleMailMessage[].class) != null) { mailSender.send(aryEq(items)); } else { mailSender.send(items); } when(mailSender).thenThrow(new MailSendException(Collections.singletonMap((Object)foo, (Exception)new MessagingException("FOO")))); writer.write(Arrays.asList(items)); assertEquals("FOO", content.get()); }
/** * @see PatientIdentifierValidator#checkIdentifierAgainstFormat(String,String,String) */ @Test public void checkIdentifierAgainstFormat_shouldIncludeFormatDescriptionInErrorMessageIfSpecified() { String format = "\\d+"; String formatDescription = "formatDescription"; String expectedErrorMessage = "Identifier \"abc\" does not match : \"formatDescription\""; Mockito.when( messageSourceService.getMessage(eq("PatientIdentifier.error.invalidFormat"), aryEq(new String[] { "abc", formatDescription }), isA(Locale.class))).thenReturn(expectedErrorMessage); expectedException.expect(InvalidIdentifierFormatException.class); //expectedException.expectMessage(expectedErrorMessage); PatientIdentifierValidator.checkIdentifierAgainstFormat("abc", format, formatDescription); }
/** * @see PatientIdentifierValidator#checkIdentifierAgainstFormat(String,String,String) */ @Test public void checkIdentifierAgainstFormat_shouldIncludeFormatInErrorMessageIfNoFormatDescriptionIsSpecified() { String format = "\\d+"; String formatDescription = null; String expectedErrorMessage = "Identifier \"abc\" does not match : \"\\d+\""; Mockito.when( messageSourceService.getMessage(eq("PatientIdentifier.error.invalidFormat"), aryEq(new String[] { "abc", format }), isA(Locale.class))).thenReturn(expectedErrorMessage); expectedException.expect(InvalidIdentifierFormatException.class); //expectedException.expectMessage(expectedErrorMessage); PatientIdentifierValidator.checkIdentifierAgainstFormat("abc", format, formatDescription); }