/** * Copyright (C) 2014 Typesafe Inc. */ package akka.stream.javadsl; import java.util.ArrayList; import java.util.List; import akka.stream.StreamTest; import akka.stream.javadsl.japi.Function2; import akka.stream.testkit.AkkaSpec; import org.junit.ClassRule; import org.junit.Test; import org.reactivestreams.Publisher; import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; import java.util.ArrayList; import java.util.List; public class SinkTest extends StreamTest { public SinkTest() { super(actorSystemResource); } @ClassRule public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("FlowTest", AkkaSpec.testConf()); @Test public void mustBeAbleToUseFanoutPublisher() throws Exception { final KeyedSink> pubSink = Sink.fanoutPublisher(2, 2); final Publisher publisher = Source.from(new ArrayList()).runWith(pubSink, materializer); } @Test public void mustBeAbleToUseFuture() throws Exception { final KeyedSink> futSink = Sink.head(); final List list = new ArrayList(); list.add(1); final Future future = Source.from(list).runWith(futSink, materializer); assert Await.result(future, Duration.create("1 second")).equals(1); } @Test public void mustBeAbleToUseFold() throws Exception { KeyedSink> foldSink = Sink.fold(0, new Function2() { @Override public Integer apply(Integer arg1, Integer arg2) throws Exception { return arg1 + arg2; } }); Future integerFuture = Source.from(new ArrayList()).runWith(foldSink, materializer); } }