Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit bf2d052

Browse files
committed
Use plain old JUnit for tests
1 parent 7b9ad3a commit bf2d052

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

Diff for: project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ project.name=maybe
55
sbt.version=0.7.7
66
project.version=0.1-SNAPSHOT
77
publish.remote=false
8-
build.scala.versions=2.9.1 2.9.0-1 2.9.0 2.8.1
8+
build.scala.versions=2.9.1 2.9.0-1 2.9.0 2.8.2 2.8.1
99
project.initialize=false

Diff for: project/build/Maybe.scala

+1-10
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,12 @@ class Maybe(info: ProjectInfo) extends DefaultProject(info) {
3131
def extraResources = "LICENSE.txt"
3232
override def mainResources = super.mainResources +++ extraResources
3333

34-
val junitInterface = "com.novocode" % "junit-interface" % "0.6" % "test->default"
34+
val junitInterface = "com.novocode" % "junit-interface" % "0.7" % "test->default"
3535

3636
override def testOptions =
3737
super.testOptions ++
3838
Seq(TestArgument(TestFrameworks.JUnit, "-q", "-v"))
3939

40-
// val lib_scalatest = "org.scalatest" %% "scalatest" % "1.4.1" % "test" withSources()
41-
val lib_scalatest = buildScalaVersion match {
42-
case "2.8.1" => "org.scalatest" % "scalatest_2.8.1" % "1.5.1" % "test" withSources()
43-
case "2.9.0" => "org.scalatest" % "scalatest_2.9.0" % "1.6.1" % "test" withSources()
44-
case "2.9.0-1" => "org.scalatest" % "scalatest_2.9.0-1" % "1.6.1" % "test" withSources()
45-
case "2.9.1" => "org.scalatest" % "scalatest_2.9.1" % "1.6.1" % "test" withSources()
46-
case v => error("Unsupported Scala version " + v)
47-
}
48-
4940
override def packageDocsJar = defaultJarPath("-javadoc.jar")
5041
override def packageSrcJar= defaultJarPath("-sources.jar")
5142
val sourceArtifact = Artifact.sources(artifactID)

Diff for: src/main/scala/com/ckkloverdos/maybe/Maybe.scala

+3-8
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ final case class Just[@specialized(Boolean, Char, Int, Double) +A](get: A) exten
150150
def filter(f: (A) => Boolean): Maybe[A] = if(f(get)) this else NoVal
151151
def foreach(f: A => Unit) = f(get)
152152

153-
protected def equalsImpl(that: Maybe[_]) = that match {
154-
case Just(v) => v == get
155-
case _ => false
156-
}
153+
protected def equalsImpl(that: Maybe[_]) =
154+
that.getClass == classOf[Just[_]] && that.asInstanceOf[Just[_]].get == this.get
157155
}
158156

159157
case object NoVal extends MaybeOption[Nothing] {
@@ -177,10 +175,7 @@ case object NoVal extends MaybeOption[Nothing] {
177175
def filter(f: (Nothing) => Boolean) = NoVal
178176
def foreach(f: Nothing => Unit) = {}
179177

180-
protected def equalsImpl(that: Maybe[_]) = that match {
181-
case NoVal => true
182-
case _ => false
183-
}
178+
protected def equalsImpl(that: Maybe[_]) = that eq NoVal
184179
}
185180

186181
/**

Diff for: src/test/scala/com/ckkloverdos/maybe/MaybeTest.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@
1616

1717
package com.ckkloverdos.maybe
1818

19-
import org.scalatest.FlatSpec
19+
import org.junit.Assert
20+
import org.junit.Test
2021

2122
/**
2223
*
2324
* @author Christos KK Loverdos <loverdos@gmail.com>.
2425
*/
2526

26-
class MaybeTest extends FlatSpec {
27-
28-
behavior of "Maybe"
29-
30-
it should ("translate null to " + NoVal) in {
31-
assert(Maybe(null) === NoVal)
27+
class MaybeTest {
28+
@Test
29+
def testNullToNoVal = {
30+
Assert.assertTrue(Maybe(null) == NoVal)
3231
}
3332

34-
it should "translate a non-null value x to Just(x)" in {
33+
@Test
34+
def testNotNullToJust = {
3535
val items = List(
3636
1,
3737
"Hello world",
3838
(x: Int) => x * x,
3939
new java.lang.Double(2.0),
40-
List(1, 2, 3)
41-
)
40+
List(1, 2, 3))
4241

4342
for(item <- items) {
44-
assert(Maybe(item) === Just(item))
43+
Assert.assertTrue(Maybe(item).isJust)
4544
}
4645
}
4746

48-
it should "translate a body that throws an exception to a Failed(exception)" in {
49-
assert(Maybe(throw new Exception).isFailed)
47+
@Test
48+
def testExceptionToFailed = {
49+
Assert.assertTrue(Maybe(throw new Exception).isFailed)
5050
}
5151
}

0 commit comments

Comments
 (0)