EP / me2day-scala
me2day API for scala
Clone this repository (size: 251.3 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/EP/me2day-scala/
| commit 33: | e608fb49e765 |
| parent 32: | bb920e1a9473 |
| branch: | default |
Add test for CreateCommentCommand.
12 months ago
Changed (Δ1.7 KB):
raw changeset »
src/main/scala/net/me2day/scala/CreateCommentCommand.scala (14 lines added, 0 lines removed)
src/main/scala/net/me2day/scala/Me2Day.scala (1 lines added, 10 lines removed)
src/test/scala/net/me2day/scala/CreateCommentCommandSpec.scala (33 lines added, 0 lines removed)
Up to file-list src/main/scala/net/me2day/scala/CreateCommentCommand.scala:
1 |
package net.me2day.scala |
|
2 |
||
3 |
class CreateCommentCommand(invocation : HttpInvocation) { |
|
4 |
def this(me2day : Me2Day, postId : String, body : String) { |
|
5 |
this(me2day.prepareInvocation("create_comment", "POST")) |
|
6 |
invocation.addParameter("post_id", postId) |
|
7 |
invocation.addParameter("body", body) |
|
8 |
} |
|
9 |
||
10 |
def execute() : ErrorResult = { |
|
11 |
invocation.resultParser.error(invocation.execute()) |
|
12 |
} |
|
13 |
} |
|
14 |
Up to file-list src/main/scala/net/me2day/scala/Me2Day.scala:
| … | … | @@ -50,7 +50,7 @@ class Me2Day(val application : Applicati |
50 |
50 |
} |
51 |
51 |
|
52 |
52 |
def createComment(postId : String, body : String) = { |
53 |
new CreateComment |
|
53 |
new CreateCommentCommand(this, postId, body) |
|
54 |
54 |
} |
55 |
55 |
|
56 |
56 |
def deleteComment(commentId : String) = { |
| … | … | @@ -107,15 +107,6 @@ class Me2Day(val application : Applicati |
107 |
107 |
|
108 |
108 |
import java.util.Date |
109 |
109 |
|
110 |
class CreateComment(me2day : Me2Day, postId : String, body : String) { |
|
111 |
def execute() : ErrorResult = { |
|
112 |
val invocation = me2day.prepareInvocation("create_comment", "POST") |
|
113 |
invocation.addParameter("post_id", postId) |
|
114 |
invocation.addParameter("body", body) |
|
115 |
invocation.resultParser.error(invocation.execute()) |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
110 |
class DeleteComment(me2day : Me2Day, commentId : String) { |
120 |
111 |
def execute() : ErrorResult = { |
121 |
112 |
val invocation = me2day.prepareInvocation("delete_comment", "POST") |
Up to file-list src/test/scala/net/me2day/scala/CreateCommentCommandSpec.scala:
1 |
package net.me2day.scala |
|
2 |
||
3 |
import java.net.URL |
|
4 |
||
5 |
import org.specs.Specification |
|
6 |
import org.specs.mock.JMocker |
|
7 |
import org.specs.mock.ClassMocker |
|
8 |
import org.specs.runner.JUnit4 |
|
9 |
||
10 |
class CreateCommentCommandTest extends JUnit4(CreateCommentCommandSpec) |
|
11 |
||
12 |
object CreateCommentCommandSpec extends Specification with JMocker with ClassMocker { |
|
13 |
var invocation : HttpInvocation = _ |
|
14 |
var dut : CreateCommentCommand = _ |
|
15 |
||
16 |
doBefore { |
|
17 |
invocation = mock[HttpInvocation] |
|
18 |
dut = new CreateCommentCommand(invocation) |
|
19 |
} |
|
20 |
||
21 |
"construction" in { |
|
22 |
val api = mock[Me2Day] |
|
23 |
val postId = "abcde" |
|
24 |
val body = "This is body" |
|
25 |
||
26 |
expect { |
|
27 |
one(api).prepareInvocation("create_comment", "POST") will returnValue(invocation) |
|
28 |
one(invocation).addParameter("post_id", postId) |
|
29 |
one(invocation).addParameter("body", body) |
|
30 |
} |
|
31 |
new CreateCommentCommand(api, postId, body) |
|
32 |
} |
|
33 |
} |
