aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-07-10 12:17:22 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-07-10 14:32:40 +0200
commit9cce261badc3089ef676a8b4ea9816890d08ee45 (patch)
treeee358e7522d9b75dec7d26730e36344eb020d6d4 /src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java
parent93dc21fea53263ecce68db2e88bb9186c42600f7 (diff)
Android: fix path bugs and enable tests on Windows
Now all tests under //src/test/j/c/g/devtools/build/android/...:* pass on Windows, yay! Also adjust test sizes as advised by Bazel (using --test_verbose_timeout_warnings). See https://github.com/bazelbuild/bazel/issues/3264 Change-Id: I3f1f4978306bdedaf805149295daa413d2248fbb PiperOrigin-RevId: 161373699
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java b/src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java
index 5c60d4dc0a..03f38e93e9 100644
--- a/src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java
+++ b/src/test/java/com/google/devtools/build/android/DensitySpecificResourceFilterTest.java
@@ -18,8 +18,10 @@ import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.Lists;
import com.google.devtools.build.android.AndroidResourceMerger.MergingException;
import java.io.IOException;
+import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
@@ -28,9 +30,10 @@ import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.EnumSet;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -219,13 +222,17 @@ public class DensitySpecificResourceFilterTest {
new DensitySpecificResourceFilter(densities, out, working);
final Path filteredResourceDir = filter.filter(tmp);
- final ImmutableList.Builder<String> filteredResources = ImmutableList.<String>builder();
+ final List<Path> filteredResources = new ArrayList<>();
try {
- Files.walkFileTree(filteredResourceDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS),
- Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
- @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
+ Files.walkFileTree(
+ filteredResourceDir,
+ EnumSet.of(FileVisitOption.FOLLOW_LINKS),
+ Integer.MAX_VALUE,
+ new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
throws IOException {
- filteredResources.add(filteredResourceDir.relativize(path).toString());
+ filteredResources.add(filteredResourceDir.relativize(path));
return FileVisitResult.CONTINUE;
}
});
@@ -233,15 +240,12 @@ public class DensitySpecificResourceFilterTest {
throw new RuntimeException(e);
}
- String[] expected = new String[] {
- "res/drawable-xxhdpi/btn_edit_pressed.png",
- "res/drawable-xxhdpi-v11/btn_edit_pressed.png",
- "res/drawable-xxhdpi-v19/btn_edit_pressed.png"
- };
- String[] actual = filteredResources.build().toArray(new String[0]);
- Arrays.sort(expected);
- Arrays.sort(actual);
- assertThat(actual).isEqualTo(expected);
+ FileSystem fs = FileSystems.getDefault();
+ assertThat(filteredResources)
+ .containsExactly(
+ fs.getPath("res/drawable-xxhdpi/btn_edit_pressed.png"),
+ fs.getPath("res/drawable-xxhdpi-v11/btn_edit_pressed.png"),
+ fs.getPath("res/drawable-xxhdpi-v19/btn_edit_pressed.png"));
}
@Before
@@ -263,24 +267,23 @@ public class DensitySpecificResourceFilterTest {
private void checkTransformedResources(List<String> resourcePaths,
List<String> expectedResourcePaths, List<String> densities) throws MergingException {
List<Path> resources = new ArrayList<>();
+ FileSystem fs = FileSystems.getDefault();
for (String resourcePath : resourcePaths) {
- resources.add(FileSystems.getDefault().getPath(resourcePath));
+ resources.add(fs.getPath(resourcePath));
}
DensitySpecificResourceFilter transformer =
new DensitySpecificResourceFilter(densities, null, null);
- List<Path> resourcesToRemove = transformer.getResourceToRemove(resources);
- List<String> actualResourcePaths = new ArrayList<>(resourcePaths);
+ Set<Path> resourcesToRemove = new HashSet<>(transformer.getResourceToRemove(resources));
+ List<String> actualResourcePaths = new ArrayList<>();
- for (Path path : resourcesToRemove) {
- actualResourcePaths.remove(path.toString());
+ for (Path p : resources) {
+ if (!resourcesToRemove.contains(p)) {
+ actualResourcePaths.add(p.toString());
+ }
}
- String[] expected = expectedResourcePaths.toArray(new String[0]);
- String[] actual = actualResourcePaths.toArray(new String[0]);
- Arrays.sort(expected);
- Arrays.sort(actual);
-
- assertThat(actual).isEqualTo(expected);
+ List<String> expected = Lists.transform(expectedResourcePaths, n -> fs.getPath(n).toString());
+ assertThat(actualResourcePaths).containsExactlyElementsIn(expected);
}
}