Skip to content
Browse files

Ref #872, #873 cleanup actor specs, adjust get timeout, make class an…

…d sus names consistent
  • Loading branch information...
1 parent 3a9f1aa commit d8da1e515553dddbe6deeb71843bf1e45d910407 @indrajitr indrajitr committed Feb 17, 2011
View
15 core/actor/src/test/java/net/liftweb/actor/MyJavaActor.java
@@ -17,24 +17,27 @@
package net.liftweb.actor;
+/**
+ * Java implementation of LiftActor for test.
+ */
public class MyJavaActor extends LiftActorJ {
private int myValue = 0;
@Receive protected void set(Set what) {
- myValue = what.num();
+ myValue = what.num();
}
@Receive public void get(Get get) {
- reply(new Answer(myValue));
+ reply(new Answer(myValue));
}
@Receive protected Answer add(Add toAdd) {
- myValue += toAdd.num();
- return new Answer(myValue);
+ myValue += toAdd.num();
+ return new Answer(myValue);
}
@Receive public Answer sub(Sub toSub) {
- myValue -= toSub.num();
- return new Answer(myValue);
+ myValue -= toSub.num();
+ return new Answer(myValue);
}
}
View
81 core/actor/src/test/scala/net/liftweb/actor/ActorSpec.scala
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 WorldWide Conferencing, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.liftweb
+package actor
+
+import org.specs.Specification
+import common._
+
+
+/**
+ * Systems under specification for Lift Actor.
+ */
+object ActorSpec extends Specification("Actor Specification") {
+
+ "A Scala Actor" should {
+ "support common features" in commonFeatures(new MyScalaActor)
+ }
+
+ "A Java Actor" should {
+ "support common features" in commonFeatures(new MyJavaActor)
+ }
+
+ private def commonFeatures(actor: LiftActor) = {
+
+ "allow setting and getting of a value" in {
+ val a = actor
+ a ! Set(33)
+ a !? Get()
+ (a.!?(50, Get())) must_== Full(Answer(33))
+ }
+
+ "allow setting and getting of a value with subclass of Get()" in {
+ val a = actor
+ a ! Set(33)
+ a ! new FunnyGet()
+ (a.!?(50L, new FunnyGet())) must_== Full(Answer(33))
+ }
+
+ "allow adding of a value" in {
+ val a = actor
+ a ! Set(33)
+ (a !< Add(44)).get(50) must_== Full(Answer(77))
+ }
+
+ "allow subtracting of a value" in {
+ val a = actor
+ a ! Set(33)
+ (a !< Sub(11)).get(50) must_== Full(Answer(22))
+ }
+
+ "properly timeout" in {
+ val a = actor
+ (a !< Set(33)).get(50) must_== Empty
+ }
+ }
+
+}
+
+
+case class Add(num: Int)
+case class Sub(num: Int)
+case class Set(num: Int)
+
+case class Get()
+class FunnyGet() extends Get()
+
+case class Answer(num: Int)
View
118 core/actor/src/test/scala/net/liftweb/actor/ActorSpecs.scala
@@ -1,118 +0,0 @@
-/*
- * Copyright 2011 WorldWide Conferencing, LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.liftweb
-package actor
-
-import common._
-
-import org.specs._
-import org.specs.specification._
-
-object ActorSpec extends Specification {
- "An Actor" should {
- def make = new MyActor
-
- "Allow setting & getting of a value" in {
- val a = make
- a ! Set(33)
- (a. !?(5L, Get())) must_== Full(Answer(33))
- }
-
- "Allow setting & getting of a value with subclass of Get()" in {
- val a = make
- a ! Set(33)
- (a. !?(5L, new FunnyGet())) must_== Full(Answer(33))
- }
-
- "Allow adding of a value" in {
- val a = make
- a ! Set(33)
- (a !< Add(44)).get(5) must_== Full(Answer(77))
- }
-
- "Allow subtracting of a value" in {
- val a = make
- a ! Set(33)
- (a !< Sub(11)).get(5) must_== Full(Answer(22))
- }
-
- "Properly timeout" in {
- val a = make
- (a !< Set(33)).get(5) must_== Empty
- }
- }
-
- "A Java Actor" should {
- def make = new MyJavaActor()
-
- "Allow setting & getting of a value" in {
- val a = make
- a ! Set(33)
- a !? Get()
- (a.!?(50, Get())) must_== Full(Answer(33))
- }
-
- "Allow setting & getting of a value with subclass of Get()" in {
- val a = make
- a ! Set(33)
- a ! new FunnyGet()
- (a. !?(50L, new FunnyGet())) must_== Full(Answer(33))
- }
-
-
- "Allow adding of a value" in {
- val a = make
- a ! Set(33)
- (a !< Add(44)).get(50) must_== Full(Answer(77))
- }
-
- "Allow subtracting of a value" in {
- val a = make
- a ! Set(33)
- (a !< Sub(11)).get(50) must_== Full(Answer(22))
- }
-
- "Properly timeout" in {
- val a = make
- (a !< Set(33)).get(50) must_== Empty
- }
- }
-}
-
-case class Add(num: Int)
-case class Sub(num: Int)
-case class Set(num: Int)
-case class Get()
-
-class FunnyGet() extends Get()
-
-case class Answer(num: Int)
-
-class MyActor extends LiftActor {
- private var value = 0
-
- override protected def messageHandler = {
- case Add(n) => value += n; reply(Answer(value))
- case Sub(n) => value -= n; reply(Answer(value))
- case Set(n) => value = n
- case Get() => reply(Answer(value))
- }
-}
-
-
-class ActorSpecTest extends _root_.org.specs.runner.JUnit4(ActorSpec)
-
View
33 core/actor/src/test/scala/net/liftweb/actor/MyScalaActor.scala
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2011 WorldWide Conferencing, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.liftweb
+package actor
+
+
+/**
+ * Scala implementation of LiftActor for test.
+ */
+class MyScalaActor extends LiftActor {
+ private var value = 0
+
+ override protected def messageHandler = {
+ case Add(n) => value += n; reply(Answer(value))
+ case Sub(n) => value -= n; reply(Answer(value))
+ case Set(n) => value = n
+ case Get() => reply(Answer(value))
+ }
+}

0 comments on commit d8da1e5

Please sign in to comment.
Something went wrong with that request. Please try again.