Skip to content

Bugfix/tests catch #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,680 changes: 2,293 additions & 2,387 deletions src/test/java/com/arangodb/ArangoCollectionTest.java

Large diffs are not rendered by default.

243 changes: 19 additions & 224 deletions src/test/java/com/arangodb/ArangoCursorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,135 +73,50 @@ public void next() {
@Test
public void mapFilterCount() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final long count = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).count();
final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).count();
assertThat(count, is(50L));
}

@Test
public void mapMapFilterCount() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final long count = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).map(new Function<Long, Long>() {
@Override
public Long apply(final Long t) {
return t * 10;
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 500;
}
}).count();
final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).count();
assertThat(count, is(50L));
}

@Test
public void mapMapFilterFilterCount() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final long count = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).map(new Function<Long, Long>() {
@Override
public Long apply(final Long t) {
return t * 10;
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 500;
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 250;
}
}).count();
final long count = cursor.map(VPackSlice::getAsLong).map(t -> t * 10).filter(t -> t < 500).filter(t -> t < 250).count();
assertThat(count, is(25L));
}

@Test
public void mapFilterNext() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final long count = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).iterator().next();
final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).iterator().next();
assertThat(count, is(0L));
}

@Test
public void mapFilterFirst() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final long count = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).first();
final long count = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).first();
assertThat(count, is(0L));
}

@Test
public void mapFilterCollectIntoList() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final List<Long> target = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).collectInto(new ArrayList<Long>());
final List<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new ArrayList<>());
assertThat(target, is(not(nullValue())));
assertThat(target.size(), is(50));
}

@Test
public void mapFilterCollectIntoSet() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final Set<Long> target = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).collectInto(new HashSet<Long>());
final Set<Long> target = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).collectInto(new HashSet<>());
assertThat(target, is(not(nullValue())));
assertThat(target.size(), is(50));
}
Expand All @@ -210,203 +125,83 @@ public boolean test(final Long t) {
public void foreach() {
final AtomicLong i = new AtomicLong(0L);
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
cursor.foreach(new Consumer<VPackSlice>() {
@Override
public void accept(final VPackSlice t) {
assertThat(t.getAsLong(), is(i.getAndIncrement()));
}
});
cursor.foreach(t -> assertThat(t.getAsLong(), is(i.getAndIncrement())));
}

@Test
public void mapForeach() {
final AtomicLong i = new AtomicLong(0L);
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).foreach(new Consumer<Long>() {
@Override
public void accept(final Long t) {
assertThat(t, is(i.getAndIncrement()));
}
});
cursor.map(VPackSlice::getAsLong).foreach(t -> assertThat(t, is(i.getAndIncrement())));
}

@Test
public void mapFilterForeach() {
final AtomicLong i = new AtomicLong(0L);
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).foreach(new Consumer<Long>() {
@Override
public void accept(final Long t) {
assertThat(t, is(i.getAndIncrement()));
}
});
cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).foreach(t -> assertThat(t, is(i.getAndIncrement())));
}

@Test
public void anyMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.anyMatch(new Predicate<VPackSlice>() {
@Override
public boolean test(final VPackSlice t) {
return t.getAsLong() == 50L;
}
});
final boolean match = cursor.anyMatch(t -> t.getAsLong() == 50L);
assertThat(match, is(true));
}

@Test
public void mapAnyMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).anyMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t == 50L;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).anyMatch(t -> t == 50L);
assertThat(match, is(true));
}

@Test
public void mapFilterAnyMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).anyMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t == 25L;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).anyMatch(t -> t == 25L);
assertThat(match, is(true));
}

@Test
public void noneMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.noneMatch(new Predicate<VPackSlice>() {
@Override
public boolean test(final VPackSlice t) {
return t.getAsLong() == 100L;
}
});
final boolean match = cursor.noneMatch(t -> t.getAsLong() == 100L);
assertThat(match, is(true));
}

@Test
public void mapNoneMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).noneMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t == 100L;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).noneMatch(t -> t == 100L);
assertThat(match, is(true));
}

@Test
public void mapFilterNoneMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).noneMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t == 50L;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).noneMatch(t -> t == 50L);
assertThat(match, is(true));
}

@Test
public void allMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.allMatch(new Predicate<VPackSlice>() {
@Override
public boolean test(final VPackSlice t) {
return t.getAsLong() < 100L;
}
});
final boolean match = cursor.allMatch(t -> t.getAsLong() < 100L);
assertThat(match, is(true));
}

@Test
public void mapAllMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).allMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 100;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).allMatch(t -> t < 100);
assertThat(match, is(true));
}

@Test
public void mapFilterAllMatch() {
final ArangoCursor<VPackSlice> cursor = db.query("FOR i IN 0..99 RETURN i", VPackSlice.class);
final boolean match = cursor.map(new Function<VPackSlice, Long>() {
@Override
public Long apply(final VPackSlice t) {
return t.getAsLong();
}
}).filter(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
}).allMatch(new Predicate<Long>() {
@Override
public boolean test(final Long t) {
return t < 50;
}
});
final boolean match = cursor.map(VPackSlice::getAsLong).filter(t -> t < 50).allMatch(t -> t < 50);
assertThat(match, is(true));
}
}
Loading