AttributeDelegator extends BaseDelegator implements IAttributeDelegator { List<IFileSpec> buildSetFileAttributesFileSpecsFromCommandResultMaps( @Nullable final List<Map<String, Object>> resultMaps, @Nonnull final Function<Map<String, Object>, IFileSpec> handle) throws RequestException { List<IFileSpec> resultList = new ArrayList<>(); if (nonNull(resultMaps)) { List<String> filesSeen = new ArrayList<>(); for (Map<String, Object> map : resultMaps) { IFileSpec spec = handle.apply(map); if (spec.getOpStatus() == VALID) { String file = spec.getAnnotatedPathString(DEPOT); if (isNotBlank(file)) { if (!filesSeen.contains(file)) { filesSeen.add(file); resultList.add(spec); } } } else { resultList.add(spec); } } } return resultList; } AttributeDelegator(IOptionsServer server); @Override List<IFileSpec> setFileAttributes(
            final List<IFileSpec> files,
            @Nonnull final Map<String, String> attributes,
            final SetFileAttributesOptions opts); @Override List<IFileSpec> setFileAttributes(
            final List<IFileSpec> files,
            @Nonnull final String attributeName,
            @Nonnull final InputStream inStream,
            final SetFileAttributesOptions opts);  }
@SuppressWarnings("unchecked") @Test public void buildSetFileAttributesFileSpecsFromCommandResultMaps_shouldReturnNonEmptyListWhenStatusIsNotValid() throws ConnectionException, AccessException, RequestException { when(mockHandle.apply(resultMap)).thenReturn(mockFileSpec); when(mockFileSpec.getOpStatus()).thenReturn(ERROR); List<IFileSpec> resultList = attributeDelegator. buildSetFileAttributesFileSpecsFromCommandResultMaps(resultMaps, mockHandle); assertThat(resultList.size(), is(1)); }
@SuppressWarnings("unchecked") @Test public void buildSetFileAttributesFileSpecsFromCommandResultMaps_shouldReturnNonEmptyListWhenStatusIsValid() throws ConnectionException, AccessException, RequestException { when(mockHandle.apply(resultMap)).thenReturn(mockFileSpec); when(mockFileSpec.getOpStatus()).thenReturn(VALID); when(mockFileSpec.getAnnotatedPathString(DEPOT)).thenReturn("not blank"); List<IFileSpec> resultList = attributeDelegator. buildSetFileAttributesFileSpecsFromCommandResultMaps(resultMaps, mockHandle); assertThat(resultList.size(), is(1)); }
@Test public void buildSetFileAttributesFileSpecsFromCommandResultMaps_shouldThrownExceptionWhenInnerCallThrown() throws ConnectionException, AccessException, RequestException { thrown.expect(ConnectionException.class); doThrow(ConnectionException.class).when(mockHandle).apply(any()); attributeDelegator. buildSetFileAttributesFileSpecsFromCommandResultMaps(resultMaps, mockHandle); }