This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
BuildConfigTest.java
97 lines (83 loc) · 3.35 KB
/
BuildConfigTest.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.facebook.buck.android;
import static org.junit.Assert.assertEquals;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.rules.AbstractBuildable;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.Buildable;
import com.facebook.buck.rules.FakeBuildRuleParams;
import com.facebook.buck.rules.FakeBuildableContext;
import com.facebook.buck.step.Step;
import com.facebook.buck.util.BuckConstant;
import org.easymock.EasyMock;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
/**
* Unit test for {@link BuildConfig}.
*/
public class BuildConfigTest {
/**
* Tests the following methods:
* <ul>
* <li>{@link Buildable#getInputsToCompareToOutput()}
* <li>{@link BuildConfig#getPathToOutputFile()}
* </ul>
*/
@Test
public void testSimpleObserverMethods() {
BuildRule buildRule = createSimpleBuildConfigRule();
BuildConfig buildConfigRule = (BuildConfig) buildRule.getBuildable();
assertEquals(
BuckConstant.GEN_PATH.resolve("java/com/example/__build_config__/BuildConfig.java"),
buildConfigRule.getPathToOutputFile());
}
@Test
public void testBuildInternal() throws IOException {
BuildRule buildRule = createSimpleBuildConfigRule();
BuildConfig buildConfigRule = (BuildConfig) buildRule.getBuildable();
// Mock out a BuildContext whose DependencyGraph will be traversed.
BuildContext buildContext = EasyMock.createMock(BuildContext.class);
EasyMock.replay(buildContext);
List<Step> steps = buildConfigRule.getBuildSteps(buildContext, new FakeBuildableContext());
Step generateBuildConfigStep = steps.get(1);
GenerateBuildConfigStep expectedStep = new GenerateBuildConfigStep(
/* appPackage */ "com.example",
/* debug */ true,
BuckConstant.GEN_PATH.resolve("java/com/example/__build_config__/BuildConfig.java"));
assertEquals(expectedStep, generateBuildConfigStep);
}
@Test
public void testGetTypeMethodOfBuilder() {
assertEquals("build_config", BuildConfigDescription.TYPE.getName());
}
private static BuildRule createSimpleBuildConfigRule() {
// First, create the BuildConfig object.
BuildTarget buildTarget = new BuildTarget("//java/com/example", "build_config");
BuildConfig buildConfig = new BuildConfig(
buildTarget,
/* appPackage */ "com.example",
/* debug */ true);
return new AbstractBuildable.AnonymousBuildRule(
BuildConfigDescription.TYPE,
buildConfig,
new FakeBuildRuleParams(buildTarget));
}
// TODO(nickpalmer): Add another unit test that passes in a non-trivial DependencyGraph and verify
// that the resulting set of libraryManifestPaths is computed correctly.
}