### Question:
Deployment { Deployment withTemporalDirectory(File temporalDirectory) { checkNotNull(temporalDirectory,"Temporal directory cannot be null"); checkArgument(temporalDirectory.isDirectory(),"Path %s cannot be used as a temporal directory (it is not a directory)",temporalDirectory.getAbsolutePath()); checkArgument(temporalDirectory.canWrite(),"Path %s cannot be used as a temporal directory (cannot be written)",temporalDirectory.getAbsolutePath()); this.temporalDirectory=temporalDirectory; return this; } private  Deployment(String contextPath, File temporalDirectory);   }### Answer:
@Test(expected=NullPointerException.class) public void testWithTemporalDirectory$nullValue() { Deployment.newInstance().withTemporalDirectory(null); }
@Test(expected=IllegalArgumentException.class) public void testWithTemporalDirectory$failIfNoDir() { File directory=new File("pom.xml"); Deployment.newInstance().withTemporalDirectory(directory); }
@Test(expected=IllegalArgumentException.class) public void testWithTemporalDirectory$failIfNoWritable() { new MockUp<File>() { @Mock boolean canWrite() { return false; } }; File directory=new File(System.getProperty("java.io.tmpdir")); Deployment.newInstance().withTemporalDirectory(directory); }
@Test public void testWithTemporalDirectory$maintainsOverride() { File directory=new File(System.getProperty("java.io.tmpdir")); String ctxConfigProperty = Deployment.contextTemporalDirectoryProperty("context"); System.setProperty(ctxConfigProperty,"ctx_dir"); System.setProperty(Deployment.APPLICATION_ENGINE_TMPDIR,"engine_dir"); try { assertThat(Deployment.newInstance().withTemporalDirectory(directory).temporalDirectory(),equalTo(directory)); } finally { System.clearProperty(ctxConfigProperty); System.clearProperty(Deployment.APPLICATION_ENGINE_TMPDIR); } }