LinuxFileAccessService implements FileAccessService { public Iterable<Result<AccessControlEntry, Boolean>> setAccess(@NotNull final AccessControlList accessControlList) { List<Result<AccessControlEntry, Boolean>> results = new ArrayList<Result<AccessControlEntry, Boolean>>(); for (AccessControlEntry ace: accessControlList) { for (Result<AccessControlEntry, Boolean> result: tryApplyAccess(ace)) { results.add(result); } } return results; } LinuxFileAccessService(@NotNull final CommandLineExecutor commandLineExecutor); Iterable<Result<AccessControlEntry, Boolean>> setAccess(@NotNull final AccessControlList accessControlList);  }
@Test(dataProvider = "getSetPermissionsForLinuxCases") public void shouldSetPermissionsForLinux( @NotNull final AccessControlList accessControlList, final int exitCode, @Nullable final Exception error, @Nullable final List<CommandLineSetup> expectedCommandLineSetups, @Nullable final List<Object> expectedResult) throws ExecutionException { final FileAccessService instance = createInstance(); final ArrayList<CommandLineSetup> actualCommandLineSetups = new ArrayList<CommandLineSetup>(); myCtx.checking(new Expectations() {{ allowing(myCommandLineExecutor).runProcess(with(any(CommandLineSetup.class)), with(any(int.class))); if(error != null) { will(throwException(error)); } else { will(new CustomAction("runProcess") { @Override public Object invoke(final Invocation invocation) throws Throwable { actualCommandLineSetups.add((CommandLineSetup)invocation.getParameter(0)); final ExecResult execResult = new ExecResult(); execResult.setExitCode(exitCode); return execResult; } }); } }}); final Iterable<Result<AccessControlEntry, Boolean>> result = instance.setAccess(accessControlList); final List<Object> actualResult = CollectionsUtil.convertCollection( Lists.newArrayList(result), new Converter<Object, Result<AccessControlEntry, Boolean>>() { @Override public Object createFrom(@NotNull final Result<AccessControlEntry, Boolean> aceResult) { if(aceResult.isSuccessful()) { return aceResult.getValue(); } return null; } }); myCtx.assertIsSatisfied(); then(actualCommandLineSetups).isEqualTo(expectedCommandLineSetups); then(actualResult).isEqualTo(expectedResult); }