Fix test ActorCreationTest.testWrongAnonymousInPlaceCreator (#30236)
* Fix test ActorCreationTest.testWrongAnonymousInPlaceCreator - added non-static check for Creator (#30220) * fix spec test
This commit is contained in:
parent
79b48ca354
commit
657386488d
3 changed files with 18 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue