Permalink
Browse files

Extracted a new PosterousPitchDectector class from the integration test

Signed-off-by: Age Mooij <age.mooij@gmail.com>
  • Loading branch information...
1 parent 7f6dfda commit 7fa2670a5a70a5b40277435d798ac2d521439630 @agemooij agemooij committed Jan 13, 2011
@@ -0,0 +1,22 @@
+package com.xebia.ai.planner
+
+
+class PosterousPitchDetector(private val repository: ProjectRepository) extends Logging {
+
+ def detectAndHandleNewPosterousPitches {
+ PosterousAPI.retrieveLatestPosts { post =>
+ if (isPitch(post)) {
+ log.info("Detected pitch on Posterous titled: %s", post.title)
+
+ // TODO: detect existing project, if not create one using this post.
+ repository.insert(post)
+ }
+ }
+ }
+
+ private def isPitch(post: PosterousPost): Boolean = {
+ val pitchPattern = ".*[pP]itch.*"
+
+ post.title.matches(pitchPattern) || post.tags.exists(_.name.matches(pitchPattern))
+ }
+}
@@ -9,22 +9,12 @@ import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class IntegrationTest extends FlatSpec with ShouldMatchers with Logging {
- val repository = new ProjectRepository with MongoTestRepository
- private def isPitch(post: PosterousPost): Boolean = {
- val pitchPattern = ".*[pP]itch.*"
+ "the PosterousPitchDetector" should "detect some pitches on Posterous" in {
+ val repository = new ProjectRepository with MongoTestRepository
+ val detector = new PosterousPitchDetector(repository)
- post.title.matches(pitchPattern) || post.tags.exists(_.name.matches(pitchPattern))
- }
-
- "the PosterousAPI" should "be able to retrieve the latest public posts" in {
- PosterousAPI.retrieveLatestPosts { post =>
- if (isPitch(post)) {
- repository.insert(post)
-
- println(post.title)
- }
- }
+ detector.detectAndHandleNewPosterousPitches
// sleep a little so we get to see the output of the asynchronous call
try {Thread.sleep(8000)} catch {case e: Exception => log.error(e, "Oops")}

0 comments on commit 7fa2670

Please sign in to comment.