@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 fn5Delegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple5<Integer, Integer, Integer, Integer, Integer>, Tuple5> invert = t5 -> new Tuple5<>(t5.getT5(), t5.getT4(), t5.getT3(), t5.getT2(), t5.getT1()); Tuple5 tuple = Tuples.fn5(invert).apply(source); assertThat(tuple.getT1()).isEqualTo(5); assertThat(tuple.getT2()).isEqualTo(4); assertThat(tuple.getT3()).isEqualTo(3); assertThat(tuple.getT4()).isEqualTo(2); assertThat(tuple.getT5()).isEqualTo(1); assertThat((Object) tuple).isExactlyInstanceOf(Tuple5.class); }
@Test public void whenDelayMonoJust5() { MonoProcessor<Tuple5<Integer, Integer, Integer, Integer, Integer>> mp = MonoProcessor.create(); StepVerifier.create(Mono.zipDelayError(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5)) .subscribeWith(mp)) .then(() -> assertThat(mp.isError()).isFalse()) .then(() -> assertThat(mp.isSuccess()).isTrue()) .then(() -> assertThat(mp.isTerminated()).isTrue()) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5).isTrue()) .verifyComplete(); }
@Test public void whenMonoJust5() { MonoProcessor<Tuple5<Integer, Integer, Integer, Integer, Integer>> mp = MonoProcessor.create(); StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5)) .subscribeWith(mp)) .then(() -> assertThat(mp.isError()).isFalse()) .then(() -> assertThat(mp.isSuccess()).isTrue()) .then(() -> assertThat(mp.isTerminated()).isTrue()) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5).isTrue()) .verifyComplete(); }
@Test public void mapT4() { Tuple5<Integer, Integer, Integer, String, Integer> base = Tuples.of(100, 200, 300, "Foo", 500); Tuple2<?,?> mapped = base.mapT4(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(5) .containsExactly(base.getT1(), base.getT2(), base.getT3(), 3, base.getT5()); }
@Test public void mapT1() { Tuple5<String, Integer, Integer, Integer, Integer> base = Tuples.of("Foo", 200, 300, 400, 500); Tuple2<?,?> mapped = base.mapT1(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(5) .containsExactly(3, base.getT2(), base.getT3(), base.getT4(), base.getT5()); }
@Test public void mapT2() { Tuple5<Integer, String, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(5) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5()); }
@Test public void mapT3() { Tuple5<Integer, Integer, String, Integer, Integer> base = Tuples.of(100, 200, "Foo", 400, 500); Tuple2<?,?> mapped = base.mapT3(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(5) .containsExactly(base.getT1(), base.getT2(), 3, base.getT4(), base.getT5()); }
/** * Returns a {@link Predicate} of {@link Tuple5} that wraps a predicate of the component values of the tuple * * @param predicate the component value predicate * @param <T1> the type of the first value * @param <T2> the type of the second value * @param <T3> the type of the third value * @param <T4> the type of the fourth value * @param <T5> the type of the fifth value * @return the wrapper predicate */ public static <T1, T2, T3, T4, T5> Predicate<Tuple5<T1, T2, T3, T4, T5>> predicate(Predicate5<T1, T2, T3, T4, T5> predicate) { return tuple -> predicate.test(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5()); }
/** * Returns a {@link Function} of {@link Tuple5} that wraps a function of the component values of the tuple * * @param function the component value function * @param <T1> the type of the first value * @param <T2> the type of the second value * @param <T3> the type of the third value * @param <T4> the type of the fourth value * @param <T5> the type of the fifth value * @param <R> the type of the result of the function * @return the wrapper function */ public static <T1, T2, T3, T4, T5, R> Function<Tuple5<T1, T2, T3, T4, T5>, R> function(Function5<T1, T2, T3, T4, T5, R> function) { return tuple -> function.apply(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5()); }
/** * Returns a {@link Consumer} of {@link Tuple5} that wraps a consumer of the component values of the tuple * * @param consumer the component value consumer * @param <T1> the type of the first value * @param <T2> the type of the second value * @param <T3> the type of the third value * @param <T4> the type of the fourth value * @param <T5> the type of the fifth value * @return the wrapper consumer */ public static <T1, T2, T3, T4, T5> Consumer<Tuple5<T1, T2, T3, T4, T5>> consumer(Consumer5<T1, T2, T3, T4, T5> consumer) { return tuple -> consumer.accept(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5()); }