@@ -0,0 +1,1236 @@
+package imagej.legacy;%0A%0Aimport static org.junit.Assert.*;%0Aimport ij.ImagePlus;%0Aimport ij.ImageStack;%0Aimport ij.process.ByteProcessor;%0A%0Aimport org.junit.Test;%0A%0A%0A%0Apublic class LegacyUtilsTest %7B%0A%0A%09/*%0A%09 * This test is illustrative of an issue in IJ1 where the internal stack gets%0A%09 * deleted in certain cases. If you setProcessor() on an ImagePlus with a%0A%09 * stack of 1 slice the stack gets deleted. A subsequent call to getStack()%0A%09 * will hatch a new one using the pixels of the current ImageProcessor.%0A%09 * Basically to avoid problems the legacy layer should never call%0A%09 * setProcessor() or if it does it should do a getStack() rather than cache%0A%09 * calls to previous getStack() calls.%0A%09 */%0A%09@Test%0A%09public void testStackKiller() %7B%0A%09%09ImageStack stack = new ImageStack(2,2);%0A%09%09byte%5B%5D slice = new byte%5B%5D%7B1,2,3,4%7D;%0A%09%09stack.addSlice(%22one slice%22, slice);%0A%09%09ImagePlus imp = new ImagePlus(%22fred%22,stack);%0A%09%09assertEquals(stack, imp.getStack());%0A%09%09byte%5B%5D slice2 = new byte%5B%5D%7B5,6,7,8%7D;%0A%09%09ByteProcessor proc = new ByteProcessor(2,2,slice2,null);%0A%09%09imp.setProcessor(proc);%0A%09%09ImageStack secondStack = imp.getStack();%0A%09%09assertNotSame(stack, secondStack);%0A%09%09assertEquals(slice, stack.getPixels(1));%0A%09%09assertEquals(slice2, secondStack.getPixels(1));%0A%09%7D%0A%7D%0A

add illustrative test for a stack death scenario to avoid in the legacy layer