Fix test ActorCreationTest.testWrongAnonymousInPlaceCreator (#30236)

* Fix test ActorCreationTest.testWrongAnonymousInPlaceCreator - added non-static check for Creator (#30220)

* fix spec test
This commit is contained in:
Andrei Arlou 2021-05-19 22:06:56 +03:00 committed by GitHub
parent 79b48ca354
commit 657386488d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View file

@ -176,21 +176,21 @@ public class ActorCreationTest extends JUnitSuite {
@Test
public void testWrongAnonymousInPlaceCreator() {
try {
Props.create(
Actor.class,
new Creator<Actor>() {
@Override
public Actor create() throws Exception {
return null;
}
});
assert false;
} catch (IllegalArgumentException e) {
assertEquals(
"cannot use non-static local Creator to create actors; make it static (e.g. local to a static method) or top-level",
e.getMessage());
}
IllegalArgumentException exception =
Assert.assertThrows(
IllegalArgumentException.class,
() ->
Props.create(
Actor.class,
new Creator<Actor>() {
@Override
public Actor create() throws Exception {
return null;
}
}));
assertEquals(
"cannot use non-static local Creator to create actors; make it static (e.g. local to a static method) or top-level",
exception.getMessage());
}
@Test

View file

@ -64,8 +64,8 @@ class PropsCreationSpec extends AkkaSpec("""
val p = Props.create(OneParamActorCreator)
system.actorOf(p)
}
"work with create(class, param)" in {
val p = Props.create(classOf[OneParamActor], null)
"work with create(class, creator)" in {
val p = Props.create(classOf[Actor], OneParamActorCreator)
system.actorOf(p)
}
}

View file

@ -75,6 +75,7 @@ private[akka] trait AbstractProps {
* Create new Props from the given [[akka.japi.Creator]] with the type set to the given actorClass.
*/
def create[T <: Actor](actorClass: Class[T], creator: Creator[T]): Props = {
checkCreatorClosingOver(creator.getClass)
create(classOf[CreatorConsumer], actorClass, creator)
}