From 06606e83dc942693dd95a30f704876c41eb4d8e5 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 20 Jun 2013 09:41:08 -0700 Subject: SI-7265 General test for spec version The test for isJavaAtLeast uses the specification.version. The method argument must have the form "major.minor". The scaladoc is updated to reflect the new reality and a test is added under junit. Note that this implementation aims to be a simple compromise between the functional and imperative camps, that is, to be free of both closures and while loops. And to elicit no cruft like regexes and wrappers for strings. No doubt even more could be done in this department, but we don't wish to spoil the fun on codegolf.stackexchange.com. However, we might decide to sponsor a new site: codereviewpingpong.com For 2.10.x, javaSpecVersion is provided as a private member. The active test is under `run` and the `junit` test must bide its time in `pending`. For 2.11, the private members can be public and the app test replaced with the unit test. --- test/pending/junit/scala/util/t7265.scala | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/pending/junit/scala/util/t7265.scala (limited to 'test/pending') diff --git a/test/pending/junit/scala/util/t7265.scala b/test/pending/junit/scala/util/t7265.scala new file mode 100644 index 0000000000..3b8fa80dbe --- /dev/null +++ b/test/pending/junit/scala/util/t7265.scala @@ -0,0 +1,46 @@ + +package scala.util +package test + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.util.PropertiesTrait + +/** The java version property uses the spec version + * and must work for all "major.minor" and fail otherwise. + */ +@RunWith(classOf[JUnit4]) +class SpecVersionTest { + val sut = new PropertiesTrait { + override def javaSpecVersion = "1.7" + + override protected def pickJarBasedOn: Class[_] = ??? + override protected def propCategory: String = "test" + + // override because of vals like releaseVersion + override lazy val scalaProps = new java.util.Properties + } + + @Test + def comparesCorrectly(): Unit = { + assert(sut isJavaAtLeast "1.5") + assert(sut isJavaAtLeast "1.6") + assert(sut isJavaAtLeast "1.7") + assert(!(sut isJavaAtLeast "1.8")) + } + @Test(expected = classOf[NumberFormatException]) + def badVersion(): Unit = { + sut isJavaAtLeast "1.a" + } + @Test(expected = classOf[NumberFormatException]) + def missingVersion(): Unit = { + sut isJavaAtLeast "1" + } + @Test(expected = classOf[NumberFormatException]) + def notASpec(): Unit = { + sut isJavaAtLeast "1.7.1" + } +} -- cgit v1.2.3