@Test public void fn7() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple7<Object, Object, Object, Object, Object, Object, Object> tuple = Tuples.fn7().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.getT7()).isEqualTo(7); assertThat(tuple) .isInstanceOf(Tuple8.class) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8); }
@Test public void fn7Delegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple7<Integer, Integer, Integer, Integer, Integer, Integer, Integer>, Tuple7> invert = t7 -> new Tuple7<>(t7.getT7(), t7.getT6(), t7.getT5(), t7.getT4(), t7.getT3(), t7.getT2(), t7.getT1()); Tuple7 tuple = Tuples.fn7(invert).apply(source); assertThat(tuple.getT1()).isEqualTo(7); assertThat(tuple.getT2()).isEqualTo(6); assertThat(tuple.getT3()).isEqualTo(5); assertThat(tuple.getT4()).isEqualTo(4); assertThat(tuple.getT5()).isEqualTo(3); assertThat(tuple.getT6()).isEqualTo(2); assertThat(tuple.getT7()).isEqualTo(1); assertThat((Object) tuple).isExactlyInstanceOf(Tuple7.class); } @Test
@Test public void whenMonoJust7() { StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5), Mono.just(6), Mono.just(7))) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6 && v.getT7() == 7).isTrue()) .verifyComplete(); }
@Test public void whenDelayMonoJust7() { MonoProcessor<Tuple7<Integer, Integer, 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), Mono.just(6), Mono.just(7))) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6 && v.getT7() == 7).isTrue()) .verifyComplete(); }
@Test public void mapT1() { Tuple7<String, Integer, Integer, Integer, Integer, Integer, Integer> base = Tuples.of("Foo", 200, 300, 400, 500, 600, 700); Tuple2<?,?> mapped = base.mapT1(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(3, base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7()); }
@Test public void mapT2() { Tuple7<Integer, String, Integer, Integer, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500, 600, 700); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7()); }
@Test public void mapT5() { Tuple7<Integer, Integer, Integer, Integer, String, Integer, Integer> base = Tuples.of(100, 200, 300, 400, "Foo", 600, 700); Tuple2<?,?> mapped = base.mapT5(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), 3, base.getT6(), base.getT7()); }
@Test public void mapT6() { Tuple7<Integer, Integer, Integer, Integer, Integer, String, Integer> base = Tuples.of(100, 200, 300, 400, 500, "Foo", 700); Tuple2<?,?> mapped = base.mapT6(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), 3, base.getT7()); }
@Test public void mapT7() { Tuple7<Integer, Integer, Integer, Integer, Integer, Integer, String> base = Tuples.of(100, 200, 300, 400, 500, 600, "Foo"); Tuple2<?,?> mapped = base.mapT7(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6(), 3); }
@Test public void mapT3() { Tuple7<Integer, Integer, String, Integer, Integer, Integer, Integer> base = Tuples.of(100, 200, "Foo", 400, 500, 600, 700); Tuple2<?,?> mapped = base.mapT3(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(7) .containsExactly(base.getT1(), base.getT2(), 3, base.getT4(), base.getT5(), base.getT6(), base.getT7()); }
/** * Returns a {@link Consumer} of {@link Tuple7} 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 * @param <T6> the type of the sixth value * @param <T7> the type of the seventh value * @return the wrapper consumer */ public static <T1, T2, T3, T4, T5, T6, T7> Consumer<Tuple7<T1, T2, T3, T4, T5, T6, T7>> consumer(Consumer7<T1, T2, T3, T4, T5, T6, T7> consumer) { return tuple -> consumer.accept(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5(), tuple.getT6(), tuple.getT7()); }
/** * Returns a {@link Predicate} of {@link Tuple7} 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 * @param <T6> the type of the sixth value * @param <T7> the type of the seventh value * @return the wrapper predicate */ public static <T1, T2, T3, T4, T5, T6, T7> Predicate<Tuple7<T1, T2, T3, T4, T5, T6, T7>> predicate(Predicate7<T1, T2, T3, T4, T5, T6, T7> predicate) { return tuple -> predicate.test(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5(), tuple.getT6(), tuple.getT7()); }
/** * Returns a {@link Function} of {@link Tuple7} 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 <T6> the type of the sixth value * @param <T7> the type of the seventh value * @param <R> the type of the result of the function * @return the wrapper function */ public static <T1, T2, T3, T4, T5, T6, T7, R> Function<Tuple7<T1, T2, T3, T4, T5, T6, T7>, R> function(Function7<T1, T2, T3, T4, T5, T6, T7, R> function) { return tuple -> function.apply(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5(), tuple.getT6(), tuple.getT7()); }