-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Colocalisation_Test window crash on multiple runs
If a script uses Colocalisation_Test, and closes the result window, subsequent attempts to run Colocalisation_Test will crash because the reference to the window will still be there, but the attempts to write to the window will crash because the window was closed. To verify, revert changes to Colocalisation_Test.java & run the new test case added - the 2nd attempt to run coloc will fail. The solution was to cleanup the window ref when a window is closed. Signed-off-by: Curtis Rueden <[email protected]>
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 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
41 changes: 41 additions & 0 deletions
41
src/test/java/sc/fiji/coloc/tests/ColocalisationGUITest.java
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,41 @@ | ||
package sc.fiji.coloc.tests; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.awt.Window; | ||
import java.awt.event.WindowEvent; | ||
|
||
import org.junit.Test; | ||
|
||
import ij.IJ; | ||
import ij.ImagePlus; | ||
import ij.WindowManager; | ||
import ij.plugin.ChannelSplitter; | ||
import sc.fiji.coloc.Colocalisation_Test; | ||
|
||
public class ColocalisationGUITest extends ColocalisationTest { | ||
@Test | ||
public void testThatWindowRefIsCleanedUpIfClosed() { | ||
ImagePlus img = IJ.openImage("http://imagej.net/images/FluorescentCells.zip"); | ||
ImagePlus[] splitImg = ChannelSplitter.split(img); | ||
Colocalisation_Test colocalisationTest = new Colocalisation_Test(); | ||
|
||
// run module once, it'll open results textWindow | ||
colocalisationTest.correlate(splitImg[0], splitImg[1], splitImg[2]); | ||
|
||
// check textWindow is open, and close it | ||
Window resultsWindow = WindowManager.getWindow("Results"); | ||
assertTrue(resultsWindow.isVisible()); | ||
resultsWindow.dispatchEvent(new WindowEvent(resultsWindow, WindowEvent.WINDOW_CLOSING)); | ||
assertFalse(resultsWindow.isVisible()); | ||
|
||
// run module again | ||
colocalisationTest.correlate(splitImg[0], splitImg[1], splitImg[2]); | ||
|
||
// check textWindow is open, .correlate didnt crash! | ||
resultsWindow = WindowManager.getWindow("Results"); | ||
assertTrue(resultsWindow.isVisible()); | ||
|
||
} | ||
} |