-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FutureToObservable and rename ObservableExtensions to IterableToO…
…bservable
David Hoepelman
committed
Dec 23, 2016
1 parent
30ec23a
commit f7222b9
Showing
3 changed files
with
129 additions
and
61 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
118 changes: 118 additions & 0 deletions
118
src/test/scala/rx/lang/scala/ScalaTypesConversionsTests.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,118 @@ | ||
package rx.lang.scala | ||
|
||
import org.junit.Test | ||
import org.scalatest.junit.JUnitSuite | ||
import rx.lang.scala.observers.TestSubscriber | ||
|
||
import scala.concurrent.Future | ||
import scala.util.{Failure, Success, Try} | ||
|
||
class ScalaTypesConversionsTests extends JUnitSuite { | ||
|
||
@Test | ||
def testIterableConversion() = { | ||
val it = Seq("1", "2", "3") | ||
val observer = TestSubscriber[String]() | ||
it.toObservable.subscribe(observer) | ||
|
||
observer.assertValues("1", "2", "3") | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testIterableEmptyConversion() = { | ||
val it = List() | ||
val observer = TestSubscriber[String]() | ||
it.toObservable.subscribe(observer) | ||
|
||
observer.assertNoValues() | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testTrySuccessConversion() = { | ||
val success = Success("abc") | ||
val observer = TestSubscriber[String]() | ||
success.toObservable.subscribe(observer) | ||
|
||
observer.assertValue("abc") | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testTryFailureConversion() = { | ||
val error = new IllegalArgumentException("test error") | ||
val failure = Failure[String](error) | ||
val observer = TestSubscriber[String]() | ||
failure.toObservable.subscribe(observer) | ||
|
||
observer.assertNoValues() | ||
observer.assertError(error) | ||
observer.assertNotCompleted() | ||
} | ||
|
||
@Test | ||
def testOptionSomeConversion() = { | ||
val some = Option("abc") | ||
val observer = TestSubscriber[String]() | ||
some.toObservable.subscribe(observer) | ||
|
||
observer.assertValue("abc") | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testOptionNoneConversion() = { | ||
val some = Option.empty[String] | ||
val observer = TestSubscriber[String]() | ||
some.toObservable.subscribe(observer) | ||
|
||
observer.assertNoValues() | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testFutureSuccessfulConversion() = { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
val fut = Future.successful("abc") | ||
val observer = TestSubscriber[String]() | ||
fut.toObservable.subscribe(observer) | ||
|
||
observer.awaitTerminalEvent() | ||
observer.assertValue("abc") | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testFutureSuccessfulConversion2() = { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
val fut = Future { "abc" } | ||
val observer = TestSubscriber[String]() | ||
fut.toObservable.subscribe(observer) | ||
|
||
observer.awaitTerminalEvent() | ||
observer.assertValue("abc") | ||
observer.assertNoErrors() | ||
observer.assertCompleted() | ||
} | ||
|
||
@Test | ||
def testFutureFailedConversion() = { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
val error = new IllegalArgumentException("test error") | ||
val fut = Future.failed(error) | ||
val observer = TestSubscriber[String]() | ||
fut.toObservable.subscribe(observer) | ||
|
||
observer.awaitTerminalEvent() | ||
observer.assertNoValues() | ||
observer.assertError(error) | ||
observer.assertNotCompleted() | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/test/scala/rx/lang/scala/TryOptionConversionsTests.scala
This file was deleted.
Oops, something went wrong.