Buggy code:
public class ServerInModuleStartupTestCase { static ServiceContainer container ; @ BeforeClass public static void startServer ( ) throws Exception { } @ AfterClass public static void testServerStartupAndShutDown ( ) throws Exception { } @ Test public void testXmlConfigDemo ( ) throws Exception { } @ Test public void testDescriptionDemo ( ) throws Exception { } @ Test public void testDeploymentStreamApi ( ) throws Exception { } @ Test public void testDeploymentFileApi ( ) throws Exception { } @ Test public void testFilesystemDeployment ( ) throws Exception { final JavaArchive archive = ShrinkWrapUtils . createJavaArchive ( "servermodule//test-deployment.sar" , Simple . class . getPackage ( ) ) ; final File dir = new File ( "target//archives" ) ; dir . mkdirs ( ) ; final File file = new File ( dir , "test-deployment.sar" ) ; archive . as ( ZipExporter . class ) . exportZip ( file , true ) ; final File deployDir = new File ( "target" , "deployments" ) ; ServerInModuleStartupTestCase . cleanFile ( deployDir ) ; deployDir . mkdirs ( ) ; Assert . assertTrue ( deployDir . exists ( ) ) ; ModelControllerClient client = Factory . create ( InetAddress . getByName ( "localhost" ) , 9999 ) ; ModelNode add = new ModelNode ( ) ; add . get ( OP ) . set ( ADD ) ; ModelNode addr = new ModelNode ( ) ; addr . add ( "subsystem" , "deployment-scanner" ) ; addr . add ( "scanner" , "test" ) ; add . get ( OP_ADDR ) . set ( addr ) ; add . get ( "path" ) . set ( deployDir . getAbsolutePath ( ) ) ; add . get ( "scan-enabled" ) . set ( true ) ; add . get ( "scan-interval" ) . set ( 1000 ) ; ModelNode result = client . execute ( add ) ; Assert . assertEquals ( SUCCESS , result . require ( OUTCOME ) . asString ( ) ) ; try { final File target = new File ( deployDir , "test-deployment.sar" ) ; <START_BUG> final File deployed = new File ( deployDir , "test-deployment.sar.isdeployed" ) ; <END_BUG> Assert . assertFalse ( target . exists ( ) ) ; testDeployments ( new ServerInModuleStartupTestCase . DeploymentExecutor ( ) { @ Override public void initialDeploy ( ) throws IOException { final InputStream in = new BufferedInputStream ( new FileInputStream ( file ) ) ; try { final OutputStream out = new BufferedOutputStream ( new FileOutputStream ( target ) ) ; try { int i = in . read ( ) ; while ( i != ( - 1 ) ) { out . write ( i ) ; i = in . read ( ) ; } } finally { StreamUtils . safeClose ( out ) ; } } finally { StreamUtils . safeClose ( in ) ; } final File dodeploy = new File ( deployDir , "test-deployment.sar.dodeploy" ) ; final OutputStream out = new BufferedOutputStream ( new FileOutputStream ( dodeploy ) ) ; try { out . write ( "test-deployment.sar" . getBytes ( ) ) ; } finally { StreamUtils . safeClose ( out ) ; } Assert . assertTrue ( dodeploy . exists ( ) ) ; } @ Override public void fullReplace ( ) throws IOException { final File dodeploy = new File ( deployDir , "test-deployment.sar.dodeploy" ) ; for ( int i = 0 ; i < 100 ; i ++ ) { if ( ! ( dodeploy . exists ( ) ) ) { break ; } try { Thread . sleep ( 10 ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; break ; } } initialDeploy ( ) ; } @ Override public void undeploy ( ) { final File dodeploy = new File ( deployDir , "test-deployment.sar.dodeploy" ) ; for ( int i = 0 ; i < 100 ; i ++ ) { if ( ( ! ( dodeploy . exists ( ) ) ) && ( deployed . exists ( ) ) ) { break ; } try { Thread . sleep ( 10 ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; break ; } } deployed . delete ( ) ; } } ) ; } finally { try { client . execute ( result . get ( COMPENSATING_OPERATION ) ) ; } catch ( Exception e ) { client . close ( ) ; } } } private void testDeployments ( ServerInModuleStartupTestCase . DeploymentExecutor deploymentExecutor ) throws Exception { } private static void cleanFile ( File toClean ) { } private interface DeploymentExecutor { void initialDeploy ( ) throws IOException { } void fullReplace ( ) throws IOException { } void undeploy ( ) throws IOException { } } private static class TestNotificationListener implements NotificationListener { private final ObjectName name ; private volatile CountDownLatch latch = new CountDownLatch ( 1 ) ; private TestNotificationListener ( ObjectName name ) { } @ Override public void handleNotification ( Notification notification , Object handback ) { } void reset ( int i ) { } void await ( ) throws Exception { } } }

Fix:
final File deployed = new File ( deployDir , "test-deployment.sar.deployed" ) ;