@Test public void testTemporalDirectory$ctxConfiguration$failNoContext() throws Exception { String configProperty = Deployment.contextTemporalDirectoryProperty(""); System.setProperty(configProperty,"directory"); try { final File file=new File("test"); final AtomicBoolean valid=new AtomicBoolean(true); final AtomicInteger tries=new AtomicInteger(0); new MockUp<Files>() { @Mock void createParentDirs(File file) throws IOException { tries.incrementAndGet(); String path = file.getParentFile().getPath(); valid.set( valid.get() && (path.equals("directory") || path.startsWith(dirName(System.getProperty("java.io.tmpdir"),"ldp4j","ctx")))); throw new IOException("failure"); } @Mock File createTempDir() { return file; } }; assertThat(Deployment.newInstance().temporalDirectory(),sameInstance(file)); assertThat(valid.get(),equalTo(true)); assertThat(tries.get(),equalTo(2)); } finally { System.clearProperty(configProperty); } }
File temporalDirectory() { if(this.temporalDirectory==null) { String ctx=this.contextPath.substring(1); File result=null; for(TemporalDirectoryFactory factory:FACTORIES) { result=factory.create(ctx); if(result!=null) { break; } } if(result==null) { result=Files.createTempDir(); } this.temporalDirectory=result; } return this.temporalDirectory; }
Deployment { File temporalDirectory() { if(this.temporalDirectory==null) { String ctx=this.contextPath.substring(1); File result=null; for(TemporalDirectoryFactory factory:FACTORIES) { result=factory.create(ctx); if(result!=null) { break; } } if(result==null) { result=Files.createTempDir(); } this.temporalDirectory=result; } return this.temporalDirectory; } }
Deployment { File temporalDirectory() { if(this.temporalDirectory==null) { String ctx=this.contextPath.substring(1); File result=null; for(TemporalDirectoryFactory factory:FACTORIES) { result=factory.create(ctx); if(result!=null) { break; } } if(result==null) { result=Files.createTempDir(); } this.temporalDirectory=result; } return this.temporalDirectory; } private  Deployment(String contextPath, File temporalDirectory); }
Deployment { File temporalDirectory() { if(this.temporalDirectory==null) { String ctx=this.contextPath.substring(1); File result=null; for(TemporalDirectoryFactory factory:FACTORIES) { result=factory.create(ctx); if(result!=null) { break; } } if(result==null) { result=Files.createTempDir(); } this.temporalDirectory=result; } return this.temporalDirectory; } private  Deployment(String contextPath, File temporalDirectory);  }
Deployment { File temporalDirectory() { if(this.temporalDirectory==null) { String ctx=this.contextPath.substring(1); File result=null; for(TemporalDirectoryFactory factory:FACTORIES) { result=factory.create(ctx); if(result!=null) { break; } } if(result==null) { result=Files.createTempDir(); } this.temporalDirectory=result; } return this.temporalDirectory; } private  Deployment(String contextPath, File temporalDirectory);   }