aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-06-28 21:22:28 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-29 09:33:15 +0200
commit36a1f0e1210a920c6850d786fd5321b4ac562867 (patch)
tree2c5a6c44753a1cefbe907cb46b954356e28fed8a /src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java
parent5b91934474a5c245f82135274b51ec4a65ef6bab (diff)
Fix extra bytes and missing resources for roboelectric tests:
*) Changed the GenerateRobolectricResourceSymbolsAction to merge duplicate namespaces from the dependency list input. *) RClassGenerator throws if an existing R.class file exists for that package. *) New test for duplicate package dependencies RELNOTES: none PiperOrigin-RevId: 160436937
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java36
1 files changed, 35 insertions, 1 deletions
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 9767c9a276..fd87c45506 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
@@ -15,6 +15,7 @@ package com.google.devtools.build.android.resources;
import static com.google.common.truth.Truth.assertThat;
+import com.android.SdkConstants;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@@ -28,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.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
@@ -120,6 +122,38 @@ public class RClassGeneratorTest {
}
@Test
+ public void checkFileWriteThrowsOnExisting() throws Exception {
+ checkFileWriteThrowsOnExisting(SdkConstants.FN_COMPILED_RESOURCE_CLASS);
+ }
+
+ @Test
+ public void checkInnerFileWriteThrowsOnExisting() throws Exception {
+ checkFileWriteThrowsOnExisting("R$string.class");
+ }
+
+ private void checkFileWriteThrowsOnExisting(String existingFile) throws Exception {
+ ResourceSymbols symbolValues =
+ createSymbolFile("R.txt", "int string ok 0x7f100001");
+ ResourceSymbols symbolsInLibrary =
+ createSymbolFile("lib.R.txt", "int string ok 0x1");
+
+ Path out = temp.resolve("classes");
+ String packageName = "com";
+ Path packageFolder = out.resolve(packageName);
+ Files.createDirectories(packageFolder);
+
+ RClassGenerator writer = RClassGenerator.with(out, symbolValues.asInitializers(), false);
+ Files.write(packageFolder.resolve(existingFile), new byte[0]);
+
+ try {
+ writer.write(packageName, symbolsInLibrary.asInitializers());
+ } catch (FileAlreadyExistsException e) {
+ return;
+ }
+ throw new Exception("Expected to throw a FileAlreadyExistsException");
+ }
+
+ @Test
public void emptyIntArrays() throws Exception {
boolean finalFields = true;
// Make sure we parse an empty array the way the R.txt writes it.
@@ -145,7 +179,7 @@ public class RClassGeneratorTest {
finalFields
);
}
-
+
static final Matcher<Throwable> NUMBER_FORMAT_EXCEPTION =
new BaseMatcher<Throwable>() {
@Override