/** * Checks that the actual iterable contains at least all of the expected elements or fails. If an * element appears more than once in the expected elements then it must appear at least that * number of times in the actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public final Ordered containsAllIn(Object[] expected) { return containsAllIn(asList(expected)); }
/** * Checks that the actual iterable contains at least all of the expected elements or fails. If an * element appears more than once in the expected elements then it must appear at least that * number of times in the actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public Ordered containsAllIn(Object[] expected) { return delegate().containsAllIn(expected); }
/** * Checks that the actual iterable contains at least all of the expected elements or fails. If an * element appears more than once in the expected elements then it must appear at least that * number of times in the actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public Ordered containsAllIn(Iterable<?> expected) { return delegate().containsAllIn(expected); }
/** Assert that the results contain the expected op codes. */ private void assertOps(List<PackageOps> pkgOps, Integer... expectedOps) { Set<Integer> actualOps = new HashSet<>(); for (PackageOps pkgOp : pkgOps) { for (OpEntry entry : pkgOp.getOps()) { actualOps.add(entry.getOp()); } } assertThat(actualOps).containsAllIn(expectedOps); } }
/** * Fails if the subject does not contain all of the given elements. If an element appears more * than once in the given elements, then it must appear at least that number of times in the * actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public Ordered containsAllIn(Iterable<?> expected) { return check().that(actualList).containsAllIn(expected); }
/** * Fails if the subject does not contain all of the given elements. If an element appears more * than once in the given elements, then it must appear at least that number of times in the * actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public Ordered containsAllIn(Iterable<?> expected) { return check().that(actualList).containsAllIn(expected); }
/** * Fails if the subject does not contain all of the given elements. If an element appears more * than once in the given elements, then it must appear at least that number of times in the * actual elements. * * <p>To also test that the contents appear in the given order, make a call to {@code inOrder()} * on the object returned by this method. The expected elements must appear in the given order * within the actual elements, but they are not required to be consecutive. */ @CanIgnoreReturnValue public Ordered containsAllIn(Iterable<?> expected) { return check().that(actualList).containsAllIn(expected); }
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void testItemsArePreloadedWithGlide() { final List<Object> objects = new ArrayList<>(); objects.add(new Object()); objects.add(new Object()); final HashSet<Object> loadedObjects = new HashSet<>(); ListPreloaderAdapter preloaderAdapter = new ListPreloaderAdapter() { @NonNull @Override public List<Object> getPreloadItems(int position) { return objects.subList(position - 11, position - 10); } @Nullable @Override public RequestBuilder<Object> getPreloadRequestBuilder(@NonNull Object item) { loadedObjects.add(item); return super.getPreloadRequestBuilder(item); } }; ListPreloader<Object> preloader = new ListPreloader<>(requestManager, preloaderAdapter, preloaderAdapter, 10); preloader.onScroll(null, 1, 10, 13); assertThat(loadedObjects).containsAllIn(objects); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestFromSupportFragmentActivity() { EasyPermissions.requestPermissions(spySupportFragmentActivity, RATIONALE, TestSupportFragmentActivity.REQUEST_CODE, ALL_PERMS); verify(spySupportFragmentActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestSupportFragmentActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestFromFragment() { EasyPermissions.requestPermissions(spyFragment, RATIONALE, TestFragment.REQUEST_CODE, ALL_PERMS); verify(spyFragment, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestFragment.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestFromAppCompatActivity() { EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestFromActivity() { EasyPermissions.requestPermissions(spyActivity, RATIONALE, TestActivity.REQUEST_CODE, ALL_PERMS); verify(spyActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCorrectlyCallback_whenOnRequestPermissionResultCalledFromActivity() { EasyPermissions.onRequestPermissionsResult(TestActivity.REQUEST_CODE, ALL_PERMS, SMS_DENIED_RESULT, spyActivity); verify(spyActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION))); verify(spyActivity, times(1)) .onPermissionsDenied(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.READ_SMS))); verify(spyActivity, never()).afterPermissionGranted(); }
@Test public void shouldCorrectlyCallback_whenOnRequestPermissionResultCalledFromAppCompatActivity() { EasyPermissions.onRequestPermissionsResult(TestAppCompatActivity.REQUEST_CODE, ALL_PERMS, SMS_DENIED_RESULT, spyAppCompatActivity); verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION))); verify(spyAppCompatActivity, times(1)) .onPermissionsDenied(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.READ_SMS))); verify(spyAppCompatActivity, never()).afterPermissionGranted(); }
@Test public void shouldCorrectlyCallback_whenOnRequestPermissionResultCalledFromFragment() { EasyPermissions.onRequestPermissionsResult(TestFragment.REQUEST_CODE, ALL_PERMS, SMS_DENIED_RESULT, spyFragment); verify(spyFragment, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestFragment.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.ACCESS_FINE_LOCATION))); verify(spyFragment, times(1)) .onPermissionsDenied(integerCaptor.capture(), listCaptor.capture()); assertThat(integerCaptor.getValue()).isEqualTo(TestFragment.REQUEST_CODE); assertThat(listCaptor.getValue()) .containsAllIn(new ArrayList<>(Collections.singletonList(Manifest.permission.READ_SMS))); verify(spyFragment, never()).afterPermissionGranted(); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestAlreadyGrantedPermissionsFromFragment() { grantPermissions(ALL_PERMS); EasyPermissions.requestPermissions(spyFragment, RATIONALE, TestFragment.REQUEST_CODE, ALL_PERMS); verify(spyFragment, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); verify(spyFragment, never()).requestPermissions(any(String[].class), anyInt()); assertThat(integerCaptor.getValue()).isEqualTo(TestFragment.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestAlreadyGrantedPermissionsFromActivity() { grantPermissions(ALL_PERMS); EasyPermissions.requestPermissions(spyActivity, RATIONALE, TestActivity.REQUEST_CODE, ALL_PERMS); verify(spyActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); verify(spyActivity, never()).requestPermissions(any(String[].class), anyInt()); assertThat(integerCaptor.getValue()).isEqualTo(TestActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void shouldCallbackOnPermissionGranted_whenRequestAlreadyGrantedPermissionsFromAppCompatActivity() { grantPermissions(ALL_PERMS); EasyPermissions.requestPermissions(spyAppCompatActivity, RATIONALE, TestAppCompatActivity.REQUEST_CODE, ALL_PERMS); verify(spyAppCompatActivity, times(1)) .onPermissionsGranted(integerCaptor.capture(), listCaptor.capture()); verify(spyAppCompatActivity, never()).requestPermissions(any(String[].class), anyInt()); assertThat(integerCaptor.getValue()).isEqualTo(TestAppCompatActivity.REQUEST_CODE); assertThat(listCaptor.getValue()).containsAllIn(ALL_PERMS); }
@Test public void testFilterConsumer() throws Exception { int msgSize = 16; String group = initConsumerGroup(); MessageSelector selector = MessageSelector.bySql("(TAGS is not null and TAGS in ('TagA', 'TagB'))"); RMQSqlConsumer consumer = ConsumerFactory.getRMQSqlConsumer(nsAddr, group, topic, selector, new RMQNormalListener(group + "_1")); Thread.sleep(3000); producer.send("TagA", msgSize); producer.send("TagB", msgSize); producer.send("TagC", msgSize); Assert.assertEquals("Not all sent succeeded", msgSize * 3, producer.getAllUndupMsgBody().size()); consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime); assertThat(producer.getAllMsgBody()) .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), consumer.getListener().getAllMsgBody())); assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2); }
@Test public void getAccountsByType_nullTypeReturnsAllAccounts() { shadowOf(am).addAccount(new Account("name_1", "type_1")); shadowOf(am).addAccount(new Account("name_2", "type_2")); shadowOf(am).addAccount(new Account("name_3", "type_3")); assertThat(am.getAccountsByType(null)).asList().containsAllIn(am.getAccounts()); }