@Test
    public void testIssue1421() throws NoSuchFieldException, IllegalAccessException {
        ScreenshotAppState screenshotAppState = new ScreenshotAppState("./", "screen_shot");

        SimpleApplication app = new SimpleApplication(new AppState[]{}) {
            // Dummy application because SimpleApp is abstract
            @Override
            public void simpleInitApp() { }
        };

        app.setAssetManager(new DesktopAssetManager(true));
        Field f1 = LegacyApplication.class.getDeclaredField("inputManager");
        f1.setAccessible(true);
        f1.set(app, new InputManager(new DummyMouseInput(), new DummyKeyInput(), null, null));

        Field f2 = LegacyApplication.class.getDeclaredField("renderManager");
        f2.setAccessible(true);
        f2.set(app, new RenderManager(new NullRenderer()));

        app.getRenderManager().createPostView("null", new Camera(1, 1));

        Assert.assertTrue(app.getStateManager().attach(screenshotAppState));
        app.getStateManager().update(0f); // Causes SAS#initialize to be called

        // Confirm that the SceneProcessor is attached.
        List<ViewPort> vps = app.getRenderManager().getPostViews();
        Assert.assertEquals(1, vps.size());
        Assert.assertEquals(1, vps.get(0).getProcessors().size());
        Assert.assertTrue(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is mapped.
        Assert.assertTrue(app.getStateManager().detach(screenshotAppState));

        app.getStateManager().update(0f); // Causes SAS#cleanup to be called

        // Check whether the SceneProcessor is still attached.
        Assert.assertEquals(0, vps.get(0).getProcessors().size());
        Assert.assertFalse(app.getInputManager().hasMapping("ScreenShot")); // Confirm that KEY_SYSRQ is unmapped.
    }
Test case for JME issue #1421: ScreenshotAppState never cleans up.
jme3-core/src/test/java/com/jme3/test/PreventCoreIssueRegressions.java