2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2019-01-02 18:55:26 +08:00
|
|
|
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
|
2015-11-23 13:16:39 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.japi.pf;
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
2019-03-19 11:25:48 +01:00
|
|
|
import org.scalatest.junit.JUnitSuite;
|
2015-11-23 13:16:39 +01:00
|
|
|
import scala.PartialFunction;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
@SuppressWarnings("serial")
|
2016-04-06 01:23:21 +02:00
|
|
|
public class PFBuilderTest extends JUnitSuite {
|
|
|
|
|
|
2015-11-23 13:16:39 +01:00
|
|
|
@Test
|
|
|
|
|
public void pfbuilder_matchAny_should_infer_declared_input_type_for_lambda() {
|
2019-01-12 04:00:53 +08:00
|
|
|
PartialFunction<String, Integer> pf =
|
|
|
|
|
new PFBuilder<String, Integer>()
|
|
|
|
|
.matchEquals("hello", s -> 1)
|
|
|
|
|
.matchAny(s -> Integer.valueOf(s))
|
|
|
|
|
.build();
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
2015-11-23 13:16:39 +01:00
|
|
|
assertTrue(pf.isDefinedAt("hello"));
|
|
|
|
|
assertTrue(pf.isDefinedAt("42"));
|
|
|
|
|
assertEquals(42, pf.apply("42").intValue());
|
|
|
|
|
}
|
|
|
|
|
}
|