Add static import convenience methods to Done and NotUsed (#25174)
* Add Done.done() convenience for static import * Add NotUsed.notUsed() convenience for static import
This commit is contained in:
parent
c8f4a17025
commit
5c401584c3
7 changed files with 25 additions and 6 deletions
|
|
@ -13,6 +13,7 @@ import org.scalatest.junit.JUnitSuite;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static akka.Done.done;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
|
|
@ -32,7 +33,7 @@ public class ActorTestKitTest extends JUnitSuite {
|
|||
public void testKitShouldSpawnActor() throws Exception {
|
||||
final CompletableFuture<Done> started = new CompletableFuture<>();
|
||||
testKit.spawn(Behaviors.setup((ctx) -> {
|
||||
started.complete(Done.getInstance());
|
||||
started.complete(done());
|
||||
return Behaviors.same();
|
||||
}));
|
||||
started.get(3, TimeUnit.SECONDS);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import org.junit.Test;
|
|||
|
||||
import akka.actor.typed.*;
|
||||
|
||||
import static akka.Done.done;
|
||||
import static akka.actor.typed.javadsl.Behaviors.*;
|
||||
|
||||
public class WatchTest extends JUnitSuite {
|
||||
|
|
@ -53,7 +54,7 @@ public class WatchTest extends JUnitSuite {
|
|||
(ctx, msg) -> unhandled(),
|
||||
(ctx, sig) -> {
|
||||
if (sig instanceof Terminated) {
|
||||
replyWhenTerminated.tell(Done.getInstance());
|
||||
replyWhenTerminated.tell(done());
|
||||
}
|
||||
return same();
|
||||
}
|
||||
|
|
@ -64,7 +65,7 @@ public class WatchTest extends JUnitSuite {
|
|||
return receive(
|
||||
(ctx, msg) -> {
|
||||
if (msg instanceof CustomTerminationMessage) {
|
||||
replyWhenReceived.tell(Done.getInstance());
|
||||
replyWhenReceived.tell(done());
|
||||
return same();
|
||||
} else {
|
||||
return unhandled();
|
||||
|
|
|
|||
|
|
@ -19,4 +19,11 @@ case object Done extends Done {
|
|||
* Java API: the singleton instance
|
||||
*/
|
||||
def getInstance(): Done = this
|
||||
|
||||
/**
|
||||
* Java API: the singleton instance
|
||||
*
|
||||
* This is equivalent to [[Done#getInstance()]], but can be used with static import.
|
||||
*/
|
||||
def done(): Done = this
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,11 @@ case object NotUsed extends NotUsed {
|
|||
* Java API: the singleton instance
|
||||
*/
|
||||
def getInstance(): NotUsed = this
|
||||
|
||||
/**
|
||||
* Java API: the singleton instance
|
||||
*
|
||||
* This is equivalent to [[NotUsed#getInstance()]], but can be used with static import.
|
||||
*/
|
||||
def notUsed(): NotUsed = this
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.concurrent.TimeoutException;
|
|||
import java.util.stream.Stream;
|
||||
import java.time.Duration;
|
||||
|
||||
import static akka.Done.done;
|
||||
import static akka.stream.testkit.StreamTestKit.PublisherProbeSubscription;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
|
@ -595,7 +596,7 @@ public class FlowTest extends StreamTest {
|
|||
.watchTermination(Keep.right())
|
||||
.to(Sink.ignore()).run(materializer);
|
||||
|
||||
assertEquals(Done.getInstance(), future.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
assertEquals(done(), future.toCompletableFuture().get(3, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import java.util.concurrent.CompletionStage;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
|
||||
import static akka.Done.done;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class KillSwitchTest extends StreamTest {
|
||||
|
|
@ -55,7 +56,7 @@ public class KillSwitchTest extends StreamTest {
|
|||
upstream.expectCancellation();
|
||||
downstream.expectComplete();
|
||||
|
||||
assertEquals(completionStage.toCompletableFuture().get(3, TimeUnit.SECONDS), Done.getInstance());
|
||||
assertEquals(completionStage.toCompletableFuture().get(3, TimeUnit.SECONDS), done());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static akka.NotUsed.notUsed;
|
||||
import static akka.stream.testkit.StreamTestKit.PublisherProbeSubscription;
|
||||
import static akka.stream.testkit.TestPublisher.ManualProbe;
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -451,7 +452,7 @@ public class SourceTest extends StreamTest {
|
|||
@SuppressWarnings("unused")
|
||||
public void mustCompileMethodsWithJavaDuration() {
|
||||
Source<NotUsed, Cancellable> tickSource = Source.tick(Duration.ofSeconds(1),
|
||||
Duration.ofMillis(500), NotUsed.getInstance());
|
||||
Duration.ofMillis(500), notUsed());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue