• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.javafx
6 
7 import javafx.application.*
8 import kotlinx.coroutines.*
9 import org.junit.*
10 import org.junit.Test
11 import kotlin.test.*
12 
13 class JavaFxDispatcherTest : TestBase() {
14     @Before
setupnull15     fun setup() {
16         ignoreLostThreads("JavaFX Application Thread", "Thread-", "QuantumRenderer-", "InvokeLaterDispatcher")
17     }
18 
19     @Test
testDelaynull20     fun testDelay() {
21         if (!initPlatform()) {
22             println("Skipping JavaFxTest in headless environment")
23             return // ignore test in headless environments
24         }
25 
26         runBlocking {
27             expect(1)
28             val job = launch(Dispatchers.JavaFx) {
29                 check(Platform.isFxApplicationThread())
30                 expect(2)
31                 delay(100)
32                 check(Platform.isFxApplicationThread())
33                 expect(3)
34             }
35             job.join()
36             finish(4)
37         }
38     }
39 
40     @Test
testImmediateDispatcherYieldnull41     fun testImmediateDispatcherYield() {
42         if (!initPlatform()) {
43             println("Skipping JavaFxTest in headless environment")
44             return // ignore test in headless environments
45         }
46 
47         runBlocking(Dispatchers.JavaFx) {
48             expect(1)
49             check(Platform.isFxApplicationThread())
50             // launch in the immediate dispatcher
51             launch(Dispatchers.JavaFx.immediate) {
52                 expect(2)
53                 yield()
54                 expect(4)
55             }
56             expect(3) // after yield
57             yield() // yield back
58             finish(5)
59         }
60     }
61 
62     @Test
testMainDispatcherToStringnull63     fun testMainDispatcherToString() {
64         assertEquals("Dispatchers.Main", Dispatchers.Main.toString())
65         assertEquals("Dispatchers.Main.immediate", Dispatchers.Main.immediate.toString())
66     }
67 }