groostav
02/07/2017, 6:53 PMclass someController(fileSystem: FancyAsyncFileSystem) {
override fun initialize() = suspending {
//things that call other suspend funs and async methods
}
@FXML fun handleWhateverAction(userAction: Event) = suspending {
val fileContent = await(fileSystem.loadFileAsync(Paths.get(textField.text)))
//things that call other suspend...
filePreviewArea.text = fileContent
}
}
and its test
class WhateverControllerTests {
@Test fun `when clicking on the whatever whatever should whatever the whatevers`(){
//setup
val fs = FakeFancyFileSystem().apply { setContent("a/b/c", "testing!") }
val controller = WhateverController(fs).apply {
textField.text = "a/b/c"
}
//act
controller.handleWhateverAction(NonDescriptEvent)
//problem: async computation started and because of the enforced `void`-ness of the java handlers, any reference to a Future object or something I can synchronize with is gone
//assert
assertThat(controller.filePreviewTextArea.text).isEqualTo("testing!")
}
}