org.hamcrest.collection.IsIterableWithSize Java Examples

The following examples show how to use org.hamcrest.collection.IsIterableWithSize. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComparisonUtilsTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@Test
void shouldCompareMapsAndReturnResultForEmptyTables()
{
    List<List<EntryComparisonResult>> result = ComparisonUtils.compareListsOfMaps(List.of(Map.of(FIRST_COLUMN, 1)),
            List.of(Map.of(SECOND_COLUMN, 1)));
    List<EntryComparisonResult> firstRowResult = result.get(0);
    EntryComparisonResult result1 = firstRowResult.get(0);
    EntryComparisonResult result2 = firstRowResult.get(1);
    Assertions.assertAll(COMPARISON_RESULT,
        () -> Assertions.assertFalse(result1.isPassed()),
        () -> Assertions.assertEquals(FIRST_COLUMN, result1.getKey()),
        () -> Assertions.assertEquals(BigDecimal.ONE, result1.getLeft()),
        () -> Assertions.assertNull(result1.getRight()),
        () -> Assertions.assertFalse(result2.isPassed()),
        () -> Assertions.assertEquals(SECOND_COLUMN, result2.getKey()),
        () -> Assertions.assertNull(result2.getLeft()),
        () -> Assertions.assertEquals(BigDecimal.ONE, result2.getRight()));
    assertThat(firstRowResult, IsIterableWithSize.iterableWithSize(2));
}
 
Example #2
Source File: TestEquivalentClasses.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
/**
 * See https://github.com/SciCrunch/SciGraph/wiki/MappingToOWL#equivalence-axioms
 */
@Test
public void testEquivalentToIntersectionOf() {
  Node x = getNode("http://example.org/x");
  Node y = getNode("http://example.org/y");
  Node z = getNode("http://example.org/z");

  assertThat("equivalence is symmetric and holds between all members.",
      GraphUtil.getRelationships(x, y, OwlRelationships.OWL_EQUIVALENT_CLASS, false),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
  assertThat("equivalence is symmetric and holds between all members.",
      GraphUtil.getRelationships(x, z, OwlRelationships.OWL_EQUIVALENT_CLASS, false),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
  assertThat("equivalence is symmetric and holds between all members.",
      GraphUtil.getRelationships(y, z, OwlRelationships.OWL_EQUIVALENT_CLASS, false),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
}
 
Example #3
Source File: ExtensibleUrlClassLoaderTest.java    From components with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicClassLoaderService() throws MalformedURLException {
    // this will check that the java service loader works on a classloader that is mutable
    new JarRuntimeInfo((URL) null, null, null);

    // given
    ExtensibleUrlClassLoader urlClassLoader = new ExtensibleUrlClassLoader(new URL[0]);
    // 2 comp installer
    assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader),
            IsIterableWithSize.<ComponentInstaller> iterableWithSize(2));

    // when
    urlClassLoader.addURL(new URL("mvn:org.talend.components/multiple-runtime-comp/0.18.0"));

    // then
    // 3 comp installer
    assertThat(ServiceLoader.load(ComponentInstaller.class, urlClassLoader),
            IsIterableWithSize.<ComponentInstaller> iterableWithSize(3));

}
 
Example #4
Source File: PlacesTest.java    From emissary with Apache License 2.0 6 votes vote down vote up
@Test
public void noServerBound() throws Exception {
    // setup
    // Namespace.unbind("EmissaryServer");

    // test
    Response response = target("places").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    PlacesResponseEntity entity = response.readEntity(PlacesResponseEntity.class);
    assertThat(entity.getLocal(), equalTo(null));
    assertThat(entity.getCluster(), equalTo(null));
    assertThat(entity.getErrors(), IsIterableWithSize.iterableWithSize(1));
    assertThat(entity.getErrors(), equalTo(UNBOUND_SERVER_ERR));

}
 
Example #5
Source File: PeersIT.java    From emissary with Apache License 2.0 6 votes vote down vote up
@Test
public void peersNoEmissaryServer() {
    // TODO Look at behavior here, we should probably throw the exception and not catch and return this value
    // setup
    Namespace.unbind("EmissaryServer");

    // test
    Response response = target("peers").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    PeersResponseEntity entity = response.readEntity(PeersResponseEntity.class);
    assertThat(entity.getLocal().getHost(), equalTo("Namespace lookup error, host unknown"));
    assertThat(entity.getErrors(), IsIterableWithSize.iterableWithSize(0));
    assertThat(entity.getLocal().getPeers(), equalTo(PEERS));
}
 
Example #6
Source File: EnumsExample.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_string_to_enum () {

	List<String> days = Lists.newArrayList(
			"WEDNESDAY", 
			"SUNDAY", 
			"MONDAY", 
			"TUESDAY", 
			"WEDNESDAY");
	
    Function<String, Day> valueOfFunction = Enums.valueOfFunction(Day.class);

	Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction);
	
	assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5));
	assertThat(daysAsEnums, IsIterableContainingInOrder.
			<Day>contains(
					Day.WEDNESDAY, 
					Day.SUNDAY, 
					Day.MONDAY, 
					Day.TUESDAY, 
					Day.WEDNESDAY));

}
 
Example #7
Source File: ReadJsonArrayTest.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Tests if {@link ReadJsonArray} can read an array from response.
 * @throws IOException If something wrong happens
 */
@Test
public void readArray() throws IOException {
    MatcherAssert.assertThat(
        "Could not read JSON array from response",
        new ReadJsonArray(
            new Fake()
        ).handleResponse(
            new Response(
                HttpStatus.SC_OK,
                Json.createArrayBuilder()
                    .add(
                        Json.createObjectBuilder()
                            .add("first", "First item")
                    ).add(
                        Json.createObjectBuilder()
                            .add("second", "Second item")
                    ).build().toString()
            )
        ),
        new IsIterableWithSize<>(
            new IsEqual<>(2)
        )
    );
}
 
Example #8
Source File: FilteredUriBuilderTest.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Tests if the {@link FilteredUriBuilder} can add filter parameters.
 */
@Test
public final void addFilterParameters() {
    final Map<String, Iterable<String>> filters = new HashMap<>();
    filters.put(
        "driver",
        Arrays.asList(
            "bridge"
        )
    );
    MatcherAssert.assertThat(
        "Did not added filter parameters to URI",
        new FilteredUriBuilder(
            new URIBuilder(), filters
        ).getQueryParams(),
        new IsIterableWithSize<>(
            new IsEqual<>(1)
        )
    );
}
 
Example #9
Source File: EnumsExample.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void transform_string_to_enum_string_converter () {

	List<String> days = Lists.newArrayList(
			"WEDNESDAY", 
			"SUNDAY", 
			"MONDAY", 
			"TUESDAY", 
			"WEDNESDAY");
	
    Function<String, Day> valueOfFunction = Enums.stringConverter(Day.class);

	Iterable<Day> daysAsEnums = Iterables.transform(days, valueOfFunction);
	
	assertThat(daysAsEnums, IsIterableWithSize.<Day>iterableWithSize(5));
	assertThat(daysAsEnums, IsIterableContainingInOrder.
			<Day>contains(
					Day.WEDNESDAY, 
					Day.SUNDAY, 
					Day.MONDAY, 
					Day.TUESDAY, 
					Day.WEDNESDAY));
}
 
Example #10
Source File: GraphApiNeighborhoodTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleAncestors_areReturned() {
  Graph graph = graphApi.getNeighbors(newHashSet(i), 10,
      newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.OUTGOING)), absent);
  assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(4));
  assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(4));
}
 
Example #11
Source File: CollectionMatchers.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void check_size_of_iterable () {
	
	List<String> cloths = Lists.newArrayList(
			"shirts", "shoes", "pants", "socks");
	
	assertThat(cloths, IsIterableWithSize.<String>iterableWithSize(4));
}
 
Example #12
Source File: TestSubClassOf.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubclass() {
  Node subclass = getNode("http://example.org/subclass");
  Node superclass = getNode("http://example.org/superclass");
  assertThat("classes should be labeled as such", subclass.hasLabel(OwlLabels.OWL_CLASS) && superclass.hasLabel(OwlLabels.OWL_CLASS));
  assertThat("subclass should be a directed relationship",
      GraphUtil.getRelationships(subclass, superclass, OwlRelationships.RDFS_SUBCLASS_OF),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
}
 
Example #13
Source File: FilterNullFromCollection.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void remove_null_from_list_guava_iterables () {

	List<String> strings = Lists.newArrayList(
			null, "www", null, 
			"leveluplunch", "com", null);

	Iterable<String> filterStrings = Iterables.filter(strings, 
			Predicates.notNull());
	
	assertThat(filterStrings, IsIterableWithSize.<String>iterableWithSize(3));
}
 
Example #14
Source File: TestSubObjectPropertyOf.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubclass() {
  Node subp = getNode("http://example.org/subproperty");
  Node superp = getNode("http://example.org/superproperty");
  assertThat("subclass should be a directed relationship",
      GraphUtil.getRelationships(subp, superp, OwlRelationships.RDFS_SUB_PROPERTY_OF),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
}
 
Example #15
Source File: TestSubAnnotationPropertyOf.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubclass() {
  Node subp = getNode("http://example.org/subproperty");
  Node superp = getNode("http://example.org/superproperty");
  assertThat("subclass should be a directed relationship",
      GraphUtil.getRelationships(subp, superp, OwlRelationships.RDFS_SUB_PROPERTY_OF),
      is(IsIterableWithSize.<Relationship> iterableWithSize(1)));
}
 
Example #16
Source File: EvidenceAspectTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void evidenceIsAdded() {
  assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(5));
  assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(1));
  aspect.invoke(graph);
  assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(6));
  assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(4));
}
 
Example #17
Source File: TinkerGraphUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void pathsAreTranslated() {
  Iterable<PropertyContainer> path = newArrayList(node, relationship, otherNode);
  TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil);
  tgu.addPath(path);
  assertThat(graph.getVertices(), is(IsIterableWithSize.<Vertex>iterableWithSize(2)));
  assertThat(graph.getEdges(), is(IsIterableWithSize.<Edge>iterableWithSize(1)));
}
 
Example #18
Source File: GraphApiNeighborhoodTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiTypedNeighborhood() {
  Graph graph = graphApi.getNeighbors(newHashSet(b), 1, 
      newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING),
          new DirectedRelationshipType(fizz, Direction.INCOMING)), absent);
  assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(3));
  assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(2));
}
 
Example #19
Source File: JoinNonVariantSegmentsWithVariantsTest.java    From dataflow-java with Apache License 2.0 5 votes vote down vote up
@Override
public Void apply(Iterable<Variant> actual) {
  assertThat(actual, CoreMatchers.hasItem(expectedSnp1));
  assertThat(actual, CoreMatchers.hasItem(expectedSnp2));
  assertThat(actual, CoreMatchers.hasItem(expectedInsert));
  assertThat(actual, IsIterableWithSize.<Variant>iterableWithSize(3));

  return null;
}
 
Example #20
Source File: OrderManagerTests.java    From salespoint with Apache License 2.0 5 votes vote down vote up
@Test // #61
void findOrdersBetween() {

	order = orderManager.save(order);
	LocalDateTime dateCreated = order.getDateCreated();

	Iterable<Order> result = orderManager.findBy(Interval.from(dateCreated).to(dateCreated.plusHours(1L)));

	assertThat(result, IsIterableWithSize.<Order> iterableWithSize(1));
	assertThat(result.iterator().next(), is(order));
}
 
Example #21
Source File: OrderManagerTests.java    From salespoint with Apache License 2.0 5 votes vote down vote up
@Test // #61
void findOrdersBetweenWhenFromToEqual() {

	order = orderManager.save(order);
	LocalDateTime dateCreated = order.getDateCreated();

	Iterable<Order> result = orderManager.findBy(Interval.from(dateCreated).to(dateCreated));

	assertThat(result, IsIterableWithSize.<Order> iterableWithSize(1));
	assertThat(result.iterator().next(), is(order));
}
 
Example #22
Source File: OrderManagerTests.java    From salespoint with Apache License 2.0 5 votes vote down vote up
@Test // #61
void findOrdersByOrderStatus_OPEN() {

	Order openOrder = new Order(user, Cash.CASH);
	openOrder = orderManager.save(openOrder);
	orderManager.save(order);

	orderManager.payOrder(order);

	Iterable<Order> openOrders = orderManager.findBy(OrderStatus.OPEN);

	assertThat(openOrders, IsIterableWithSize.<Order> iterableWithSize(1));
	assertThat(openOrders.iterator().next(), is(openOrder));
}
 
Example #23
Source File: ThriftScribeLoggerTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void requestIsCorrectlyCreated() {
  ThriftService<FrontendRequest, FrontendResponse> thriftService = createDefaultListener();
  logger = new ThriftScribeLogger(thriftService, executorService);
  logger.log(CATEGORY, LINES);

  // Test request outside as otherwise an assertion could fail silently.
  assertEquals(request.getType(), FrontendRequestType.LOG);
  assertEquals(request.getLogRequest().getType(), LogRequestType.SCRIBE_DATA);
  assertEquals(request.getLogRequest().getScribeData().getCategory(), CATEGORY);
  assertThat(
      request.getLogRequest().getScribeData().getLines(),
      Matchers.allOf(
          hasItem(LINES.get(0)), hasItem(LINES.get(1)), IsIterableWithSize.iterableWithSize(2)));
}
 
Example #24
Source File: OptionalExample.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void present_instances () {
	
	List<Optional<PullRequest>> pullRequests = Lists.newArrayList();
	pullRequests.add(getPullRequestUsingGuavaOptional());
	pullRequests.add(Optional.of(new PullRequest("Graham", "a->b summary",  "please merge")));
	pullRequests.add(getPullRequestUsingGuavaOptional());
	pullRequests.add(Optional.of(new PullRequest("Jesse", "c->d summary",  "check code")));
	
	Iterable<PullRequest> presentInstances = Optional.presentInstances(pullRequests);
	
	assertThat(presentInstances, IsIterableWithSize.<PullRequest>iterableWithSize(2));
}
 
Example #25
Source File: UnixDockerITCase.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * UnixDocker can list {@link Volumes}.
 * @throws Exception If something goes wrong.
 */
@Test
public void listVolumes() throws Exception {
    final Docker docker = new UnixDocker(
        Paths.get("/var/run/docker.sock").toFile()
    );
    MatcherAssert.assertThat(
        docker.volumes(),
        new IsIterableWithSize<>(new GreaterOrEqual<>(0))
    );
}
 
Example #26
Source File: LocalDockerITCase.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * LocalUnixDocker can list {@link Volumes}.
 * @throws Exception If something goes wrong.
 */
@Test
public void listVolumes() throws Exception {
    final Docker docker = new LocalDocker(
        Paths.get("/var/run/docker.sock").toFile()
    );
    MatcherAssert.assertThat(
        docker.volumes(),
        new IsIterableWithSize<>(new GreaterOrEqual<>(0))
    );
}
 
Example #27
Source File: PlacesTest.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Test
public void places() throws Exception {
    Namespace.bind("EmissaryServer", server);
    Namespace.bind("PickupPlace", "pickupPlace");
    Namespace.bind("PickupClient", "pickupClient");
    Namespace.bind("ThisWontBeAdded", "miss");
    Namespace.bind("ProcessingPlace", "processingPlace");

    // test
    Response response = target("places").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    PlacesResponseEntity entity = response.readEntity(PlacesResponseEntity.class);
    assertThat(entity.getLocal().getHost(), equalTo("localhost:8001"));
    assertThat(entity.getLocal().getPlaces(), IsIterableWithSize.iterableWithSize(3));
    assertThat(entity.getLocal().getPlaces(), equalTo(EXPECTED_PLACES));
    assertThat(entity.getErrors(), IsIterableWithSize.iterableWithSize(0));
    assertThat(entity.getCluster(), equalTo(null));

    // cleanup
    Namespace.unbind("EmissaryServer");
    Namespace.unbind("PickupPlace");
    Namespace.unbind("PickupClient");
    Namespace.unbind("ThisWontBeAdded");
    Namespace.unbind("ProcessingPlace");
}
 
Example #28
Source File: PlacesTest.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Test
public void placesNoPlacesClientsBound() throws Exception {
    Namespace.bind("EmissaryServer", server);

    // test
    Response response = target("places").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    PlacesResponseEntity entity = response.readEntity(PlacesResponseEntity.class);
    assertThat(entity.getLocal().getHost(), equalTo("localhost:8001"));
    assertThat(entity.getLocal().getPlaces(), IsIterableWithSize.iterableWithSize(0));
    assertThat(entity.getErrors(), IsIterableWithSize.iterableWithSize(0));
    assertThat(entity.getCluster(), equalTo(null));
}
 
Example #29
Source File: IterableOfTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void reportTotalPagedLength() throws Exception {
    final Iterable<String> first = new IterableOf<>("A", "five");
    final Iterable<String> second = new IterableOf<>("word", "long");
    final Iterable<String> third = new IterableOf<>("sentence");
    final Iterable<Iterable<String>> service = new IterableOf<>(
        first, second, third
    );
    final Iterator<Iterable<String>> pages = service.iterator();
    MatcherAssert.assertThat(
        "length must be equal to total number of elements",
        new IterableOf<>(
            () -> pages.next().iterator(),
            page -> new Ternary<>(
                () -> pages.hasNext(),
                () -> pages.next().iterator(),
                () -> new IteratorOf<String>()
            ).value()
        ),
        new IsIterableWithSize<>(
            new IsEqual<>(
                new LengthOf(
                    new Joined<>(first, second, third)
                ).intValue()
            )
        )
    );
}
 
Example #30
Source File: PeersCommandIT.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPeersWithPort() throws IOException {
    // test
    Set<String> peers = PeersCommand.getPeers(HostAndPort.fromString(""), true);

    // verify
    assertThat(peers, IsIterableContainingInOrder.contains("localhost:7001", "localhost:8001", "localhost:9001"));
    assertThat(peers, IsIterableWithSize.iterableWithSize(3));
}