-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from pedorich-n/option-companion-object-methods
Option.when and Option.unless added
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
compat/src/test/scala/test/scala/collection/OptionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Scala (https://www.scala-lang.org) | ||
* | ||
* Copyright EPFL and Lightbend, Inc. | ||
* | ||
* Licensed under Apache License 2.0 | ||
* (http://www.apache.org/licenses/LICENSE-2.0). | ||
* | ||
* See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. | ||
*/ | ||
|
||
package test.scala.collection | ||
|
||
import scala.collection.compat._ | ||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
class OptionTest { | ||
|
||
private val value: String = "example" | ||
private val some: Option[String] = Some(value) | ||
private val none: Option[String] = None | ||
|
||
@Test | ||
def testWhenTrue: Unit = { | ||
val option = Option.when(true)(value) | ||
assertEquals(option, some) | ||
} | ||
|
||
@Test | ||
def testWhenFalse: Unit = { | ||
val option = Option.when(false)(value) | ||
assertEquals(option, none) | ||
} | ||
|
||
@Test | ||
def testUnlessTrue: Unit = { | ||
val option = Option.unless(true)(value) | ||
assertEquals(option, none) | ||
} | ||
|
||
@Test | ||
def testUnlessFalse: Unit = { | ||
val option = Option.unless(false)(value) | ||
assertEquals(option, some) | ||
} | ||
} |