Skip to content

Commit

Permalink
Build snapshot for Scala 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
arashi01 committed Jun 16, 2016
1 parent bbbbfe4 commit 51c26bc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 32 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Expand Up @@ -6,7 +6,7 @@ site.settings

ghpages.settings

version := "0.4.0"
version := "0.5.0-SNAPSHOT"

organization := "codes.reactive"

Expand All @@ -24,7 +24,7 @@ publishOSS

scalaVersion := crossScalaVersions.value.head

crossScalaVersions := Seq("2.11.8", "2.10.6")
crossScalaVersions := Seq("2.11.8", "2.10.6", "2.12.0-M4")

libraryDependencies ++= Seq("org.scalatest" %% "scalatest" % "3.0.0-RC2" % Test)

Expand Down
3 changes: 0 additions & 3 deletions src/main/scala/codes/reactive/scalatime/control/Catcher.scala
Expand Up @@ -53,9 +53,6 @@ object Catcher {
case _ => false
}, f)(implicitly[ClassTag[Ex]])

/** $Obt all [[DateTimeException]]s. */
def all[A]: Catcher[A] = catcher[A, DateTimeException](throw _)

/** $Obt all [[DateTimeException]]s.
*
* @param f function to execute if the exception is encountered.
Expand Down
87 changes: 60 additions & 27 deletions src/test/scala/codes/reactive/scalatime/control/CatchersSuite.scala
@@ -1,39 +1,72 @@
/******************************************************************
* See the NOTICE file distributed with this work for additional *
* information regarding Copyright ownership. The author/authors *
* license this file to you under the terms of the Apache License *
* Version 2.0 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the *
* License at: *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, *
* either express or implied. See the License for the specific *
* language governing permissions and limitations under the *
* License. *
******************************************************************/
/** ****************************************************************
* See the NOTICE file distributed with this work for additional *
* information regarding Copyright ownership. The author/authors *
* license this file to you under the terms of the Apache License *
* Version 2.0 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the *
* License at: *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, *
* either express or implied. See the License for the specific *
* language governing permissions and limitations under the *
* License. *
* *****************************************************************/

package codes.reactive.scalatime
package control

import java.time.{LocalTime, LocalDate}
import java.time.temporal.{IsoFields, UnsupportedTemporalTypeException}
import java.time.DateTimeException
import java.time.format.DateTimeParseException
import java.time.temporal.UnsupportedTemporalTypeException
import java.time.zone.ZoneRulesException

import org.scalatest.{Matchers, FunSuite}
import org.scalatest.{FunSuite, Matchers}

import scala.util.{Success, Try}
import scala.util.{Failure, Success, Try}


class CatchersSuite extends FunSuite with Matchers {

test("Catcher provides 'Catcher' instances for all 'DateTimeException' instances") {
val t = Try(LocalDate.parse(")(&#)(@*@&#%@#%@#%)")).recover(Catcher.all(_ => LocalDate.of(2014, 7, 13)))
val t1 = Try(LocalTime.now().get(IsoFields.DAY_OF_QUARTER)).recover(Catcher.unsupportedTemporalType(throw _))
t shouldEqual Success(LocalDate.of(2014, 7, 13))
t1.isFailure shouldEqual true
intercept[UnsupportedTemporalTypeException](t1.get)
case class Exceptions(base: Throwable = new DateTimeException("test"),
temporalType: Throwable = new UnsupportedTemporalTypeException("test"),
zoneRules: Throwable = new ZoneRulesException("test"),
parse: Throwable = new DateTimeParseException("test", "", 0))


test("Catcher instances do not match unrelated Throwables") {
val es = Exceptions()
(Try(throw new RuntimeException).recover(Catcher.all(_ true)) orElse Success(false)) shouldBe Success(false)
(Try(throw new RuntimeException).recover(Catcher.dateTimeParseException(_ true)) orElse Success(false)) shouldBe Success(false)
(Try(throw new RuntimeException).recover(Catcher.unsupportedTemporalType(_ true)) orElse Success(false)) shouldBe Success(false)
(Try(throw new RuntimeException).recover(Catcher.zoneRules(_ true)) orElse Success(false)) shouldBe Success(false)
}

test("Catcher.all matches all 'DateTimeException' instances") {
val es = Exceptions()
Try(throw es.base).recover(Catcher.all(_ true)) shouldBe Success(true)
Try(throw es.zoneRules).recover(Catcher.all(_ true)) shouldBe Success(true)
}

test("Catcher.dateTimeParseException matches 'DateTimeParseException' instances") {
val es = Exceptions()
Try(throw es.parse).recover(Catcher.dateTimeParseException(_ true)) shouldBe Success(true)
Try(throw es.zoneRules).recover(Catcher.dateTimeParseException(_ true)) shouldBe Failure(es.zoneRules)
}

test("Catcher.unsupportedTemporalType matches 'UnsupportedTemporalTypeException' instances") {
val es = Exceptions()
Try(throw es.temporalType).recover(Catcher.unsupportedTemporalType(_ true)) shouldBe Success(true)
Try(throw es.zoneRules).recover(Catcher.unsupportedTemporalType(_ true)) shouldBe Failure(es.zoneRules)
}

test("Catcher.zoneRules matches 'ZoneRulesException' instances") {
val es = Exceptions()
Try(throw es.zoneRules).recover(Catcher.zoneRules(_ true)) shouldBe Success(true)
Try(throw es.temporalType).recover(Catcher.zoneRules(_ true)) shouldBe Failure(es.temporalType)
}

}

0 comments on commit 51c26bc

Please sign in to comment.