diff options
author | Janek Bogucki <janekdb@gmail.com> | 2016-03-31 22:07:04 +0100 |
---|---|---|
committer | Janek Bogucki <janekdb@gmail.com> | 2016-03-31 22:07:04 +0100 |
commit | 20d262c0bb6615708ce95c399f9f842b4e93bb3c (patch) | |
tree | ca4752c9c4c2124ca051158082134840aca7c13e /test/junit | |
parent | 4fc7d5517c7152d43745960efde5042febe29422 (diff) | |
download | scala-20d262c0bb6615708ce95c399f9f842b4e93bb3c.tar.gz scala-20d262c0bb6615708ce95c399f9f842b4e93bb3c.tar.bz2 scala-20d262c0bb6615708ce95c399f9f842b4e93bb3c.zip |
Add initial unit test for Catch and augment documentation
- Add unit test for andFinally
- Reduce code duplication in andFinally
- Extend documentation
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/util/control/ExceptionTest.scala | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/junit/scala/util/control/ExceptionTest.scala b/test/junit/scala/util/control/ExceptionTest.scala new file mode 100644 index 0000000000..5211d31839 --- /dev/null +++ b/test/junit/scala/util/control/ExceptionTest.scala @@ -0,0 +1,42 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2016-2016, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.util + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import org.junit.Assert._ + +import scala.collection.mutable.ListBuffer + +import scala.util.control.Exception._ + +@RunWith(classOf[JUnit4]) +class ExceptionTest { + + @Test + def andFinally(): Unit = { + + locally { + val audit = ListBuffer[Int]() + val katch = nonFatalCatch[Unit].andFinally(audit append 1) + val result = katch(10) + assertEquals(result, 10) + assertEquals(audit.toList, 1 :: Nil) + } + + locally { + val audit = ListBuffer[Int]() + val katch = nonFatalCatch[Unit].andFinally(audit append 1).andFinally(audit append 2) + val result = katch(20) + assertEquals(result, 20) + assertEquals(audit.toList, 1 :: 2 :: Nil) + } + } +}
\ No newline at end of file |