-
Notifications
You must be signed in to change notification settings - Fork 25
/
Chapter07Spec.scala
63 lines (48 loc) · 1.68 KB
/
Chapter07Spec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import org.scalatest.{FlatSpec, Matchers}
import scala.collection.mutable
class Chapter07Spec extends FlatSpec with Matchers {
"puzzler" should "use a package com that isn’t at the top level" in {
com.FromCom.value shouldBe 1
import puzzler._
com.FromCom.value shouldBe 21
}
"random" should "has nextInt, nextDouble, and setSeed functions" in {
random.nextInt() shouldBe 1013904223
random.nextDouble() shouldBe (((1013904223 * 1664525) + 1013904223)/(Int.MaxValue + 1.0))
random.setSeed(1)
random.nextInt() shouldBe 1015568748
}
"Chapter0706" should "copy all elements from a Java hash map into a Scala hash map" in {
//given
val javaHashMap = new java.util.HashMap[String, Int]
javaHashMap.put("A", 1)
javaHashMap.put("B", 2)
javaHashMap.put("C", 3)
//when
val scalaHashMap: mutable.HashMap[String, Int] = Chapter0706.fromJavaHashMap(javaHashMap)
//then
scalaHashMap.size shouldBe javaHashMap.size
scalaHashMap("A") shouldBe 1
scalaHashMap("B") shouldBe 2
scalaHashMap("C") shouldBe 3
}
"Chapter0709" should "print to error stream if password is not secret" in {
//given
val password = "wrong"
//when
val (exit, _, err) = TestUtils.runAppWithInput(password, "Chapter0709")
//then
exit shouldBe 1
err.contains("Wrong password!") shouldBe true
}
it should "print greeting to standard output if password is secret" in {
//given
val password = "secret"
//when
val (exit, out, err) = TestUtils.runAppWithInput(password, "Chapter0709")
//then
exit shouldBe 0
out.contains("Welcome " + System.getProperty("user.name")) shouldBe true
err shouldBe ""
}
}