Last active
December 26, 2015 22:59
-
-
Save balopat/7226715 to your computer and use it in GitHub Desktop.
Hardcoded dependency on time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.balopat.timeinjection | |
import java.util.Date | |
class Wall { | |
var messages = List[Message]() | |
def message(message: String) { | |
messages ::= Message(message, new Date()) // hardcoded dependency on time!!! | |
} | |
} | |
case class Message(message: String, createdAt: Date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.balopat.timeinjection | |
import org.scalatest.FlatSpec | |
import java.util.Date | |
import org.scalatest.matchers.ShouldMatchers | |
class WallSpec extends FlatSpec with ShouldMatchers { | |
"messages" should "be written in reverse order on the wall" in { | |
val wall = new Wall | |
val timeAtFirst = new Date() | |
wall.message("Hello World!") | |
val timeAtSecond = new Date() | |
wall.message("Hello, HelloWorld!") | |
wall.messages should equal( | |
List(Message("Hello, HelloWorld!", timeAtSecond), //sometime equals sometime doesn't | |
Message("Hello World!", timeAtFirst)) //sometime equals sometime doesn't | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment