1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2  * Any copyright is dedicated to the Public Domain.
3    http://creativecommons.org/publicdomain/zero/1.0/ */
4 package org.mozilla.geckoview.test
5 
6 import org.junit.Test
7 import org.mozilla.geckoview.GeckoResult
8 import org.mozilla.geckoview.test.util.Environment
9 
10 import org.hamcrest.Matchers.*
11 import org.junit.Assert.assertThat
12 
13 val env = Environment()
14 
pollDefaultnull15 fun <T> GeckoResult<T>.pollDefault(): T? =
16         this.poll(env.defaultTimeoutMillis)
17 
18 class GeckoResultTestKotlin {
19     class MockException : RuntimeException()
20 
21     @Test fun pollIncompleteWithValue() {
22         val result = GeckoResult<Int>()
23         val thread = Thread { result.complete(42) }
24 
25         thread.start()
26         assertThat("Value should match", result.pollDefault(), equalTo(42))
27     }
28 
29     @Test(expected = MockException::class) fun pollIncompleteWithError() {
30         val result = GeckoResult<Void>()
31 
32         val thread = Thread { result.completeExceptionally(MockException()) }
33         thread.start()
34 
35         result.pollDefault()
36     }
37 }