ScreenshotCommand extends Command { String getFirstElementInPath(Path path) { if (path.getNameCount() < 2) { throw new IllegalArgumentException(); } return path.getName(0).toString(); }  @Override void execute();  }
@Test public void testGetFirstElementInPath() throws CommandException { ScreenshotCommand screenshotCommand = new ScreenshotCommand(); String firstName = screenshotCommand.getFirstElementInPath(Paths.get("fr-FR/file.png")); assertEquals("fr-FR", firstName); }
@Test public void testGetFirstElementInPathMultiLevel() throws CommandException { ScreenshotCommand screenshotCommand = new ScreenshotCommand(); String firstName = screenshotCommand.getFirstElementInPath(Paths.get("fr-FR/directory/file.png")); assertEquals("fr-FR", firstName); }
@Test(expected = IllegalArgumentException.class) public void testGetFirstElementInPathNoDir() throws CommandException { ScreenshotCommand screenshotCommand = new ScreenshotCommand(); screenshotCommand.getFirstElementInPath(Paths.get("file.png")); }