/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre> * * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher); }
/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is equal to the specified * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre> * * @param item * the item to compare against the items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item); }
/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre> * * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher); }
/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is equal to the specified * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre> * * @param item * the item to compare against the items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item); }
/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is equal to the specified * <code>item</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem("bar"))</pre> * * @param item * the item to compare against the items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(T item) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(item); }
/** * Creates a matcher for {@link Iterable}s that only matches when a single pass over the * examined {@link Iterable} yields at least one item that is matched by the specified * <code>itemMatcher</code>. Whilst matching, the traversal of the examined {@link Iterable} * will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))</pre> * * @param itemMatcher * the matcher to apply to items provided by the examined {@link Iterable} */ public static <T> org.hamcrest.Matcher<java.lang.Iterable<? super T>> hasItem(org.hamcrest.Matcher<? super T> itemMatcher) { return org.hamcrest.core.IsCollectionContaining.<T>hasItem(itemMatcher); }
/** * Creates a matcher for {@link Iterable}s that matches when consecutive passes over the * examined {@link Iterable} yield at least one item that is equal to the corresponding * item from the specified <code>items</code>. Whilst matching, each traversal of the * examined {@link Iterable} will stop as soon as a matching item is found. * <p/> * For example: * <pre>assertThat(Arrays.asList("foo", "bar", "baz"), hasItems("baz", "foo"))</pre> * * @param items * the items to compare against the items provided by the examined {@link Iterable} */ @Factory public static <T> Matcher<Iterable<T>> hasItems(T... items) { List<Matcher<? super Iterable<T>>> all = new ArrayList<Matcher<? super Iterable<T>>>(items.length); for (T element : items) { all.add(hasItem(element)); } return allOf(all); }
@Override protected Matcher<?> createMatcher() { return hasItem(equalTo("irrelevant")); }
public void testMatchesACollectionThatContainsAnElementMatchingTheGivenMatcher() { Matcher<Iterable<? super String>> itemMatcher = hasItem(equalTo("a")); assertMatches("should match list that contains 'a'", itemMatcher, asList("a", "b", "c")); }
public void testHasAReadableDescription() { assertDescription("a collection containing \"a\"", hasItem(equalTo("a"))); }
public void testDoesNotMatchCollectionThatDoesntContainAnElementMatchingTheGivenMatcher() { final Matcher<Iterable<? super String>> matcher1 = hasItem(mismatchable("a")); assertMismatchDescription("mismatches were: [mismatched: b, mismatched: c]", matcher1, asList("b", "c")); final Matcher<Iterable<? super String>> matcher2 = hasItem(equalTo("a")); assertMismatchDescription("was empty", matcher2, new ArrayList<String>()); }
@Test public void recordingFileThatShouldDescribeTheTestResultAtThePresentTime() throws Exception { File vncRecordingDirectory = Files.createTempDirectory("recording").toFile(); Description description = createTestDescription(getClass().getCanonicalName(), methodName, Test.class); File recordingFile = factory.recordingFileForTest(vncRecordingDirectory, description, success); String expectedFilePrefix = format("%s-%s-%s", prefix, getClass().getSimpleName(), methodName); List<File> expectedPossibleFileNames = Arrays.asList( new File(vncRecordingDirectory, format("%s-%s.flv", expectedFilePrefix, now().format(DATETIME_FORMATTER))), new File(vncRecordingDirectory, format("%s-%s.flv", expectedFilePrefix, now().minusSeconds(1L).format(DATETIME_FORMATTER))) ); assertThat(expectedPossibleFileNames, hasItem(recordingFile)); } }
public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24 { final Set<Number> s = new HashSet<Number>(); s.add(Integer.valueOf(2)); assertThat(s, new IsCollectionContaining<Number>(new IsEqual<Number>(Integer.valueOf(2)))); assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2))); }
/** * Ensures the {@link ClusteringCacheManagerServiceConfigurationParser} is locatable as a * {@link CacheManagerServiceConfigurationParser} instance. */ @Test public void testServiceLocator() throws Exception { assertThat(stream(spliterator(ClassLoading.servicesOfType(CacheManagerServiceConfigurationParser.class).iterator(), Long.MAX_VALUE, 0), false).map(Object::getClass).collect(Collectors.toList()), hasItem(ClusteringCacheManagerServiceConfigurationParser.class)); }
@Test public void testServiceLocator() throws Exception { assertThat(stream(spliterator(ClassLoading.servicesOfType(ServiceFactory.class).iterator(), Long.MAX_VALUE, 0), false).map(Object::getClass).collect(Collectors.toList()), hasItem(ClusteringServiceFactory.class)); } }
@Test public void canGetGroupsWithExternalMember() { addMember("g1", "m1", "MEMBER", zone.getId()); addMember("g2", "m1", "MEMBER", zone.getId()); Set<ScimGroup> groups = dao.getGroupsWithExternalMember("m1", zone.getId()); assertThat(groups.size(), equalTo(2)); List<String> groupIds = groups.stream().map(ScimGroup::getId).collect(Collectors.toList()); assertThat(groupIds, hasItem("g1")); assertThat(groupIds, hasItem("g2")); }
@Test public void testAllExtensions() { URL resource = XmlConfigurationTest.class.getResource("/configs/all-extensions.xml"); Configuration config = new XmlConfiguration(new XmlConfiguration(resource)); assertThat(config.getServiceCreationConfigurations(), IsCollectionContaining.hasItem(instanceOf(BarConfiguration.class))); CacheConfiguration<?, ?> cacheConfiguration = config.getCacheConfigurations().get("fancy"); assertThat(cacheConfiguration.getServiceConfigurations(), hasItem(instanceOf(FooConfiguration.class))); assertThat(cacheConfiguration.getResourcePools().getResourceTypeSet(), hasItem(instanceOf(BazResource.Type.class))); }
@Test public void testOneCacheConfig() throws Exception { URL resource = XmlConfigurationTest.class.getResource("/configs/one-cache.xml"); Configuration config = new XmlConfiguration(new XmlConfiguration(resource)); assertThat(config.getServiceCreationConfigurations(), hasSize(0)); assertThat(config.getCacheConfigurations().keySet(), hasItem("bar")); assertThat(config.getCacheConfigurations().get("bar").getServiceConfigurations(), IsCollectionContaining.hasItem(instanceOf(FooConfiguration.class))); }
@Test public void testOneServiceConfig() throws Exception { URL resource = XmlConfigurationTest.class.getResource("/configs/one-service.xml"); Configuration config = new XmlConfiguration(new XmlConfiguration(resource)); assertThat(config.getServiceCreationConfigurations(), IsCollectionContaining.hasItem(instanceOf(BarConfiguration.class))); assertThat(config.getCacheConfigurations().keySet(), hasSize(0)); }
@Test public void testArguments() throws Exception { final RequiredArgumentBuilder<Object, ?> argument = argument("bar", integer()); builder.then(argument); assertThat(builder.getArguments(), hasSize(1)); assertThat(builder.getArguments(), hasItem((CommandNode<Object>) argument.build())); }