diff options
author | cushon <cushon@google.com> | 2018-01-04 19:14:40 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-04 19:16:54 -0800 |
commit | bbebe815a2580904f095583364770f5f6bf71dbb (patch) | |
tree | 5e452333926acd2b1a252815cedf087b782287cb /src/test/java/com | |
parent | a483876e8cbee32a87d1cc5290a1cdb9e6e6488e (diff) |
Automatic code cleanup.
PiperOrigin-RevId: 180878300
Diffstat (limited to 'src/test/java/com')
-rw-r--r-- | src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java | 11 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java | 24 |
2 files changed, 23 insertions, 12 deletions
diff --git a/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java b/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java index 29cd4c1645..3ef07f39aa 100644 --- a/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java +++ b/src/test/java/com/google/devtools/build/android/dexer/DexFileSplitterTest.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import java.io.IOException; +import java.nio.file.DirectoryStream; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; @@ -229,8 +230,8 @@ public class DexFileSplitterTest { options.inclusionFilterJar = inclusionFilterJar; DexFileSplitter.splitIntoShards(options); assertThat(options.outputDirectory.toFile().exists()).isTrue(); - ImmutableSet<Path> files = - ImmutableSet.copyOf(Files.newDirectoryStream(options.outputDirectory, "*.zip")); + ImmutableSet<Path> files = readFiles(options.outputDirectory, "*.zip"); + ImmutableList.Builder<Path> result = ImmutableList.builder(); for (int i = 1; i <= files.size(); ++i) { Path path = options.outputDirectory.resolve(i + ".shard.zip"); @@ -240,6 +241,12 @@ public class DexFileSplitterTest { return result.build(); // return expected files in sorted order } + private static ImmutableSet<Path> readFiles(Path directory, String glob) throws IOException { + try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, glob)) { + return ImmutableSet.copyOf(stream); + } + } + private Path buildDexArchive() throws Exception { return buildDexArchive(INPUT_JAR, "libtests.dex.zip"); } diff --git a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java index fd87c45506..4a6c3d343e 100644 --- a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java +++ b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java @@ -29,6 +29,7 @@ import java.lang.reflect.Modifier; import java.net.URL; import java.net.URLClassLoader; import java.nio.charset.StandardCharsets; +import java.nio.file.DirectoryStream; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; @@ -384,16 +385,19 @@ public class RClassGeneratorTest { private static void checkFilesInPackage(Path packageDir, String... expectedFiles) throws IOException { - ImmutableList<String> filesInPackage = ImmutableList - .copyOf(Iterables.transform(Files.newDirectoryStream(packageDir), - new Function<Path, String>() { - @Override - public String apply(Path path) { - return path.getFileName().toString(); - } - } - )); - assertThat(filesInPackage).containsExactly((Object[]) expectedFiles); + try (DirectoryStream<Path> stream = Files.newDirectoryStream(packageDir)) { + ImmutableList<String> filesInPackage = + ImmutableList.copyOf( + Iterables.transform( + stream, + new Function<Path, String>() { + @Override + public String apply(Path path) { + return path.getFileName().toString(); + } + })); + assertThat(filesInPackage).containsExactly((Object[]) expectedFiles); + } } private static Class<?> checkTopLevelClass( |