### Question:
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);  }### Answer:
@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)); } }
@Test public void unsupportedModeInstructionThrowsAppropriateException() { final Set<PosixFilePermission> toAdd = EnumSet.noneOf(PosixFilePermission.class); final Set<PosixFilePermission> toRemove = EnumSet.noneOf(PosixFilePermission.class); String instruction; instruction = "u-X"; try { ModeParser.parseOne(instruction, toAdd, toRemove); shouldHaveThrown(UnsupportedOperationException.class); } catch (UnsupportedOperationException e) { assertThat(e) .isExactlyInstanceOf(UnsupportedOperationException.class) .hasMessage(instruction); } instruction = "a+r"; try { ModeParser.parseOne(instruction, toAdd, toRemove); shouldHaveThrown(UnsupportedOperationException.class); } catch (UnsupportedOperationException e) { assertThat(e) .isExactlyInstanceOf(UnsupportedOperationException.class) .hasMessage(instruction); } }
@Test @UseDataProvider("validModeInstructions") public void validModeInstructionAddsInstructionsInAppropriateSets( final String instruction, final Set<PosixFilePermission> add, final Set<PosixFilePermission> remove) { final Set<PosixFilePermission> toAdd = EnumSet.noneOf(PosixFilePermission.class); final Set<PosixFilePermission> toRemove = EnumSet.noneOf(PosixFilePermission.class); ModeParser.parseOne(instruction, toAdd, toRemove); assertThat(toAdd).isEqualTo(add); assertThat(toRemove).isEqualTo(remove); }