@Test public void toHashSet_with_size_builds_an_ArrayList() { Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(toHashSet(30)); assertThat(res).isInstanceOf(HashSet.class) .containsExactly(1, 2, 3, 4, 5); }
@Test public void toSet_builds_an_ImmutableSet() { Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(toSet()); assertThat(res).isInstanceOf(ImmutableSet.class) .containsExactly(1, 2, 3, 4, 5); }
@Test public void toHashSet_builds_an_HashSet() { Set<Integer> res = Arrays.asList(1, 2, 3, 4, 5).stream().collect(toHashSet()); assertThat(res).isInstanceOf(HashSet.class) .containsExactly(1, 2, 3, 4, 5); }
@Test public void toSet_with_size_builds_an_ImmutableSet() { Set<Integer> res = Stream.of(1, 2, 3, 4, 5).collect(toSet(30)); assertThat(res).isInstanceOf(ImmutableSet.class) .containsExactly(1, 2, 3, 4, 5); }
@Test public void toEnumSet_with_empty_stream() { Set<MyEnum> res = Stream.<MyEnum>empty().collect(MoreCollectors.toEnumSet(MyEnum.class)); assertThat(res).isInstanceOf(EnumSet.class) .isEmpty(); }
@Test public void toEnumSet() { Set<MyEnum> res = Stream.of(MyEnum.ONE, MyEnum.ONE, MyEnum.TWO).collect(MoreCollectors.toEnumSet(MyEnum.class)); assertThat(res).isInstanceOf(EnumSet.class) .containsExactly(MyEnum.ONE, MyEnum.TWO); }
@Test public void spscArrayQueuesAPI() { assertThat(Queues.xs().get()).isInstanceOf(SpscArrayQueue.class); }
@Test public void mpscQueuesAPI() { assertThat(Queues.unboundedMultiproducer().get()).isInstanceOf(MpscLinkedQueue.class); }
@Test public void fn2() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple2<Object, Object> tuple = Tuples.fn2().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test @SuppressWarnings("unchecked") public void fnAny() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple2<Object, Object> tuple = Tuples.fnAny().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void fn3() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple3<Object, Object, Object> tuple = Tuples.fn3().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple.getT3()).isEqualTo(3); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void fn4() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple4<Object, Object, Object, Object> tuple = Tuples.fn4().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple.getT3()).isEqualTo(3); assertThat(tuple.getT4()).isEqualTo(4); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void broadcastOnIssueChange_passes_immutable_set_of_ChangedIssues() { QGChangeEventListenersImpl underTest = new QGChangeEventListenersImpl(new QGChangeEventListener[] {listener1}); underTest.broadcastOnIssueChange(oneIssueOnComponent1, singletonList(component1QGChangeEvent)); ArgumentCaptor<Set<ChangedIssue>> changedIssuesCaptor = newSetCaptor(); inOrder.verify(listener1).onIssueChanges(same(component1QGChangeEvent), changedIssuesCaptor.capture()); assertThat(changedIssuesCaptor.getValue()).isInstanceOf(ImmutableSet.class); }
@Test public void fn5() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple5<Object, Object, Object, Object, Object> tuple = Tuples.fn5().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple.getT3()).isEqualTo(3); assertThat(tuple.getT4()).isEqualTo(4); assertThat(tuple.getT5()).isEqualTo(5); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void fn6() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple6<Object, Object, Object, Object, Object, Object> tuple = Tuples.fn6().apply(source); assertThat(tuple.getT1()).isEqualTo(1); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple.getT3()).isEqualTo(3); assertThat(tuple.getT4()).isEqualTo(4); assertThat(tuple.getT5()).isEqualTo(5); assertThat(tuple.getT6()).isEqualTo(6); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void quequablePool() { ThreadPoolExecutor singlePool = ThreadPoolBuilder.queuableCachedPool().build(); assertThat(singlePool.getCorePoolSize()).isEqualTo(0); assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE); assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10); assertThat(singlePool.getQueue()).isInstanceOf(ControllableQueue.class); singlePool.shutdown(); ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.queuableCachedPool().setMinSize(10).setMaxSize(100) .setKeepAliveSecs(20).build(); assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10); assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100); assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20); sizeablePool.shutdown(); ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.queuableCachedPool() .setThreadNamePrefix("queuableCachedPool").build(); Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() { @Override public void run() { } }); assertThat(thread.getName()).startsWith("queuableCachedPool"); fixPoolWithNamePrefix.shutdown(); } }
private <C extends Collection<String>> void testCollectionType(GenericType<C> genericType) { Type containerType = genericType.getType(); Class<?> erasedType = getErasedType(containerType); assertThat(factory.accepts(containerType)).isTrue(); assertThat(factory.accepts(erasedType)).isFalse(); assertThat(factory.elementType(containerType)).contains(String.class); Collector<String, ?, C> collector = (Collector<String, ?, C>) factory.build(containerType); assertThat(Stream.of("foo", "bar", "baz").collect(collector)) .isInstanceOf(erasedType) .containsOnly("foo", "bar", "baz"); } }
@Test public void tupleProvidesTupleTypeHierarchy() { Tuple3<String, Long, Integer> t3 = Tuples.of("string", 1L, 10); assertThat(t3).as("Tuple3 is also a Tuple2").isInstanceOf(Tuple2.class); }
@Test public void testOptionWithinObjectIfMissingShouldBeNone() { final SomethingWithOption result = dbRule.getSharedHandle() .registerRowMapper(ConstructorMapper.factory(SomethingWithOption.class)) .createQuery("select id, name from something where id = 2") .mapTo(SomethingWithOption.class) .findOnly(); assertThat(result.getName()).isInstanceOf(Option.class); assertThat(result).isEqualTo(new SomethingWithOption(2, Option.none())); }
@Test public void testOptionMappedWithinObjectIfPresentShouldContainValue() { final SomethingWithOption result = dbRule.getSharedHandle() .registerRowMapper(ConstructorMapper.factory(SomethingWithOption.class)) .createQuery("select id, name from something where id = 1") .mapTo(SomethingWithOption.class) .findOnly(); assertThat(result.getName()).isInstanceOf(Option.class); assertThat(result).isEqualTo(new SomethingWithOption(1, Option.of("eric"))); }