1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package com.android.builder.internal;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import junit.framework.TestCase;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
@SuppressWarnings("ResultOfMethodCallIgnored")
public class BuildConfigGeneratorTest extends TestCase {
public void testFalse() throws Exception {
File tempDir = Files.createTempDir();
BuildConfigGenerator generator = new BuildConfigGenerator(tempDir.getPath(),
"my.app.pkg", false);
generator.generate(Collections.<String>emptyList());
File file = generator.getBuildConfigFile();
assertTrue(file.exists());
String actual = Files.toString(file, Charsets.UTF_8);
assertEquals(
"/** Automatically generated file. DO NOT MODIFY */\n"
+ "package my.app.pkg;\n"
+ "\n"
+ "public final class BuildConfig {\n"
+ " public static final boolean DEBUG = false;\n"
+ "\n"
+ "}", actual);
file.delete();
tempDir.delete();
}
public void testTrue() throws Exception {
File tempDir = Files.createTempDir();
BuildConfigGenerator generator = new BuildConfigGenerator(tempDir.getPath(),
"my.app.pkg", true);
generator.generate(Collections.<String>emptyList());
File file = generator.getBuildConfigFile();
assertTrue(file.exists());
String actual = Files.toString(file, Charsets.UTF_8);
assertEquals(
"/** Automatically generated file. DO NOT MODIFY */\n"
+ "package my.app.pkg;\n"
+ "\n"
+ "public final class BuildConfig {\n"
+ " public static final boolean DEBUG = Boolean.parseBoolean(\"true\");\n"
+ "\n"
+ "}", actual);
file.delete();
tempDir.delete();
}
public void testExtra() throws Exception {
File tempDir = Files.createTempDir();
BuildConfigGenerator generator = new BuildConfigGenerator(tempDir.getPath(),
"my.app.pkg", false);
generator.generate(Arrays.asList("// Extra line:", "public static int EXTRA = 42;"));
File file = generator.getBuildConfigFile();
assertTrue(file.exists());
String actual = Files.toString(file, Charsets.UTF_8);
assertEquals(
"/** Automatically generated file. DO NOT MODIFY */\n"
+ "package my.app.pkg;\n"
+ "\n"
+ "public final class BuildConfig {\n"
+ " public static final boolean DEBUG = false;\n"
+ "\n"
+ " // Extra line:\n"
+ " public static int EXTRA = 42;\n"
+ "}", actual);
file.delete();
tempDir.delete();
}
}
|