public ServerData(int port, PersistentList resources, ApplicationContext rootContext, String baseUrlPattern, Module module) { this.port = port; this.module = module; this.resources = resources==null ? Seq.of() :resources; this.rootContext = rootContext; this.baseUrlPattern = baseUrlPattern; } public ServerData(int port, List resources,
@Test public void indexOfSlize(){ assertThat(empty().indexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.nothing())); assertThat(of(1,2,3).indexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.just(0l))); assertThat(of(1).indexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.nothing())); assertThat(of(0,1,2,3).indexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.just(1l))); } @Test
@Test public void lastIndexOfSlize(){ assertThat(empty().lastIndexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.nothing())); assertThat(of(1,2,3).lastIndexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.just(0l))); assertThat(of(1).lastIndexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.nothing())); assertThat(of(0,1,2,3,4,5,6,1,2,3).lastIndexOfSlice(Seq.of(1,2,3)),equalTo(Maybe.just(7l))); } @Test
default <R> Validated<E,Seq<R>> traverse(Iterable<Validated<E,T>> seq,Function<? super T,? extends R> fn){ return ReactiveSeq.fromIterable(seq) .prepend(this) .foldLeft(Validated.<E,Seq<R>>valid(Seq.<R>empty()),(a, b)-> a.combine(Semigroups.<R>seqConcat(),b.map(v->Seq.of(fn.apply(v))))); }
@Test public void nullPublisher() { assertThat(LazyEither4.fromPublisher(Seq.of(null, 190)), not(equalTo(LazyEither4.right(null)))); } @Test
@Test public void nullPublisher() { assertThat(LazyEither3.fromPublisher(Seq.of(null, 190)), not(equalTo(LazyEither3.right(null)))); } @Test
@Test public void reducer2(){ Reducer<Integer,Integer> sum = Reducer.of(0,a->b->a+b,i->(int)i); Reducer<Integer,Integer> mult = Reducer.of(1,a->b->a*b,i->(int)i); val result = Streams.reduce(Stream.of(1,2,3,4),Arrays.asList(sum,mult)); assertThat(result,equalTo(Seq.of(10,24))); }
@Test public void fromNull(){ System.out.println(LazyEither3.fromIterable(Seq.of().plus(null))); assertThat(LazyEither3.right(null), equalTo(LazyEither3.right(null))); assertThat(LazyEither3.fromIterable(Seq.of()),equalTo(LazyEither3.left1(null))); assertThat(LazyEither3.fromPublisher(Seq.of(null,190)),not(equalTo(LazyEither3.right(null)))); assertTrue(LazyEither3.fromPublisher(Seq.of(null,190)).isLeft1()); assertThat(LazyEither3.fromFuture(Future.ofResult(null)),equalTo(LazyEither3.right(null))); } @Test
@Test public void fromNull(){ System.out.println(Option.fromIterable(Seq.of().plus(null))); assertThat(Option.some(null), not(equalTo(Option.none()))); assertThat(Option.none(), not(equalTo(Option.some(null)))); assertThat(Option.fromIterable(Seq.of()),equalTo(Option.none())); assertThat(Option.fromIterable(Seq.of().plus(null)),equalTo(Option.some(null))); // System.out.println(Option.fromPublisher(Seq.of(null,190))); // assertThat(Option.fromPublisher(Seq.of(null,190)),equalTo(Option.some(null))); assertThat(Option.fromFuture(Future.ofResult(null)),equalTo(Option.some(null))); } @Test
@Test public void windowWhile(){ assertThat(of(1,2,3,4,5,6) .groupedWhile(i->i%3!=0) .toList().size(),equalTo(2)); assertThat(of(1,2,3,4,5,6) .groupedWhile(i->i%3!=0) .toList().get(0),equalTo(Seq.of(1,2,3))); } @Test
@Test public void orElseUseAccumulating(){ assertThat(invalid.orElseUseAccumulating(()->valid),equalTo(valid)); assertThat(valid.orElseUseAccumulating(()->Validated.valid(100)),equalTo(valid)); assertThat(invalid.orElseUseAccumulating(()->invalid), not(equalTo(invalid))); assertThat(invalid.orElseUseAccumulating(()->invalid), equalTo(invalid.sequence(Seq.of(invalid)))); }
@Test public void traverse(){ Managed<Seq<Future<String>>> writers = Managed.traverse(Seq.of("a", "b", "c"),this::acquireNamed); Try<Seq<Future<String>>, Throwable> t = writers.run(); assertTrue(t.isSuccess()); assertThat(t.map(s->s.map(f->f.orElse("-1")).join(",")).orElse("-"),equalTo("A,B,C")); } @Test
@Test public void mergeOne(){ StepVerifier.create(Spouts.merge(Spouts.of(Spouts.of(1)))) .expectNext(1) .verifyComplete(); StepVerifier.create(Spouts.mergeLatestList(Seq.of(Spouts.of(1)))) .expectNext(1) .verifyComplete(); StepVerifier.create(Spouts.merge(Spouts.of(Spouts.of(1)))) .expectNext(1) .verifyComplete(); }