From 9a7fa0fbac6262fda4343fdce17b62701ac6ace0 Mon Sep 17 00:00:00 2001 From: Manuel Mauky Date: Tue, 16 Jun 2015 15:14:39 +0200 Subject: [PATCH] #260 small changes to (sometimes) failing test. --- .../utils/commands/CompositeCommandTest.java | 76 ++++++++----------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/commands/CompositeCommandTest.java b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/commands/CompositeCommandTest.java index 56e4ba9a0..ad9d7b103 100644 --- a/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/commands/CompositeCommandTest.java +++ b/mvvmfx/src/test/java/de/saxsys/mvvmfx/utils/commands/CompositeCommandTest.java @@ -189,57 +189,43 @@ protected void action() throws Exception { CompositeCommand compositeCommand = new CompositeCommand(delegateCommand1, delegateCommand2, delegateCommand3); - compositeCommand.progressProperty().addListener(new ChangeListener() { - - @Override - public void changed(ObservableValue observable, Number oldValue, Number newValue) { - } - }); - GCVerifier.forceGC(); - compositeCommand.runningProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue && !oldValue) { - Platform.runLater(new Runnable() { - @Override - public void run() { - assertTrue(compositeCommand.runningProperty().get()); - assertTrue(delegateCommand1.runningProperty().get()); - assertTrue(delegateCommand2.runningProperty().get()); - assertTrue(delegateCommand3.runningProperty().get()); - assertFalse(compositeCommand.notRunningProperty().get()); - assertFalse(delegateCommand1.notRunningProperty().get()); - assertFalse(delegateCommand2.notRunningProperty().get()); - assertFalse(delegateCommand3.notRunningProperty().get()); - commandCompleted.complete(null); - } - }); - } - if (oldValue && !newValue) { - Platform.runLater(new Runnable() { - @Override - public void run() { - assertFalse(compositeCommand.runningProperty().get()); - assertFalse(delegateCommand1.runningProperty().get()); - assertFalse(delegateCommand2.runningProperty().get()); - assertFalse(delegateCommand3.runningProperty().get()); - assertTrue(compositeCommand.notRunningProperty().get()); - assertTrue(delegateCommand1.notRunningProperty().get()); - assertTrue(delegateCommand2.notRunningProperty().get()); - assertTrue(delegateCommand3.notRunningProperty().get()); - commandStarted.complete(null); - } - }); - } + compositeCommand.runningProperty().addListener((observable, oldValue, newValue) -> { + if (newValue && !oldValue) { // command is now running, wasn't running before + Platform.runLater(() -> { + assertTrue(compositeCommand.runningProperty().get()); + assertTrue(delegateCommand1.runningProperty().get()); + assertTrue(delegateCommand2.runningProperty().get()); + assertTrue(delegateCommand3.runningProperty().get()); + assertFalse(compositeCommand.notRunningProperty().get()); + assertFalse(delegateCommand1.notRunningProperty().get()); + assertFalse(delegateCommand2.notRunningProperty().get()); + assertFalse(delegateCommand3.notRunningProperty().get()); + + commandStarted.complete(null); + }); + } + if (oldValue && !newValue) { // command was running, isn't running now + Platform.runLater(() -> { + assertFalse(compositeCommand.runningProperty().get()); + assertFalse(delegateCommand1.runningProperty().get()); + assertFalse(delegateCommand2.runningProperty().get()); + assertFalse(delegateCommand3.runningProperty().get()); + assertTrue(compositeCommand.notRunningProperty().get()); + assertTrue(delegateCommand1.notRunningProperty().get()); + assertTrue(delegateCommand2.notRunningProperty().get()); + assertTrue(delegateCommand3.notRunningProperty().get()); + + commandCompleted.complete(null); + }); } }); compositeCommand.execute(); - commandStarted.get(3, TimeUnit.SECONDS); - future.get(3, TimeUnit.SECONDS); - commandCompleted.get(4, TimeUnit.SECONDS); + commandStarted.get(5, TimeUnit.SECONDS); + future.get(5, TimeUnit.SECONDS); + commandCompleted.get(5, TimeUnit.SECONDS); }