@Test @UseDataProvider(value = "invalidModeInstructions") public void invalidModeInstructionThrowsAppropriateException(final String instruction) { final Set<PosixFilePermission> toAdd = EnumSet.noneOf(PosixFilePermission.class); final Set<PosixFilePermission> toRemove = EnumSet.noneOf(PosixFilePermission.class); try { ModeParser.parseOne(instruction, toAdd, toRemove); shouldHaveThrown(RuntimeException.class); } catch (RuntimeException e) { assertThat(e) .isExactlyInstanceOf(RuntimeException.class) .hasMessage(String.format("Invalid unix mode expresson: '%s'", instruction)); } }
static void parseOne(final String instruction, final Set<PosixFilePermission> toAdd, final Set<PosixFilePermission> toRemove) { final int plus = instruction.indexOf('+'); final int minus = instruction.indexOf('-'); if (plus < 0 && minus < 0) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } final String who; final String what; final Set<PosixFilePermission> set; if (plus >= 0) { who = plus == 0 ? "ugo" : instruction.substring(0, plus); what = instruction.substring(plus + 1); set = toAdd; } else { who = minus == 0 ? "ugo" : instruction.substring(0, minus); what = instruction.substring(minus + 1); set = toRemove; } if (what.isEmpty()) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } modifySet(who, what, set, instruction); }
ModeParser { static void parseOne(final String instruction, final Set<PosixFilePermission> toAdd, final Set<PosixFilePermission> toRemove) { final int plus = instruction.indexOf('+'); final int minus = instruction.indexOf('-'); if (plus < 0 && minus < 0) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } final String who; final String what; final Set<PosixFilePermission> set; if (plus >= 0) { who = plus == 0 ? "ugo" : instruction.substring(0, plus); what = instruction.substring(plus + 1); set = toAdd; } else { who = minus == 0 ? "ugo" : instruction.substring(0, minus); what = instruction.substring(minus + 1); set = toRemove; } if (what.isEmpty()) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } modifySet(who, what, set, instruction); } }
ModeParser { static void parseOne(final String instruction, final Set<PosixFilePermission> toAdd, final Set<PosixFilePermission> toRemove) { final int plus = instruction.indexOf('+'); final int minus = instruction.indexOf('-'); if (plus < 0 && minus < 0) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } final String who; final String what; final Set<PosixFilePermission> set; if (plus >= 0) { who = plus == 0 ? "ugo" : instruction.substring(0, plus); what = instruction.substring(plus + 1); set = toAdd; } else { who = minus == 0 ? "ugo" : instruction.substring(0, minus); what = instruction.substring(minus + 1); set = toRemove; } if (what.isEmpty()) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } modifySet(who, what, set, instruction); } private  ModeParser(); }
ModeParser { static void parseOne(final String instruction, final Set<PosixFilePermission> toAdd, final Set<PosixFilePermission> toRemove) { final int plus = instruction.indexOf('+'); final int minus = instruction.indexOf('-'); if (plus < 0 && minus < 0) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } final String who; final String what; final Set<PosixFilePermission> set; if (plus >= 0) { who = plus == 0 ? "ugo" : instruction.substring(0, plus); what = instruction.substring(plus + 1); set = toAdd; } else { who = minus == 0 ? "ugo" : instruction.substring(0, minus); what = instruction.substring(minus + 1); set = toRemove; } if (what.isEmpty()) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } modifySet(who, what, set, instruction); } private  ModeParser(); static PermissionsSet buildPermissionsSet(final String instructions); }
ModeParser { static void parseOne(final String instruction, final Set<PosixFilePermission> toAdd, final Set<PosixFilePermission> toRemove) { final int plus = instruction.indexOf('+'); final int minus = instruction.indexOf('-'); if (plus < 0 && minus < 0) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } final String who; final String what; final Set<PosixFilePermission> set; if (plus >= 0) { who = plus == 0 ? "ugo" : instruction.substring(0, plus); what = instruction.substring(plus + 1); set = toAdd; } else { who = minus == 0 ? "ugo" : instruction.substring(0, minus); what = instruction.substring(minus + 1); set = toRemove; } if (what.isEmpty()) { throw new RuntimeException("Invalid unix mode expresson: '" + instruction + "'"); } modifySet(who, what, set, instruction); } private  ModeParser(); static PermissionsSet buildPermissionsSet(final String instructions);  }