Touch implements Command<CommandInvocation> { private void touch(Resource r, CommandInvocation ci) throws IOException { if (r.exists()) { if (changeOnlyAccessTime) { r.setLastAccessed(System.currentTimeMillis()); } if (changeOnlyModificationTime) { r.setLastModified(System.currentTimeMillis()); } } else { if (!noCreate) { create(r, ci); } } }  @Override CommandResult execute(CommandInvocation ci);  }
@Test public void testTouch() throws IOException, CommandRegistryException { prepare(Touch.class, Ls.class); String tempPath = tempDir.toFile().getAbsolutePath() + Config.getPathSeparator(); pushToOutput("touch " + tempPath + "file01.txt"); assertTrue(new File(tempPath+"file01.txt").exists()); pushToOutput("touch -a " + tempPath + "file01.txt"); assertTrue(new File(tempPath+"file01.txt").exists()); pushToOutput("touch -c " + tempPath + "file02.txt"); assertFalse(new File(tempPath+"file02.txt").exists()); pushToOutput("touch -m " + tempPath + "file02.txt"); assertTrue(new File(tempPath+"file02.txt").exists()); }