summaryrefslogtreecommitdiff
path: root/java/testing.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-03-23 15:23:33 +0000
committer Paul Duffin <paulduffin@google.com> 2021-03-24 08:27:04 +0000
commit3c84eaaa984805936e71d678ffd67032beefb2c8 (patch)
tree28b3858503e1ff330653b465f0cbd734d969e96f /java/testing.go
parentf8e3d8341aec34c42a600ad5c9b13e0f41215f53 (diff)
Separate methods used for fixture based and legacy tests
The fixture mechanism makes it easy to refactor by splitting up an existing preparer into separate ones and then combining them back together. Unfortunately, that becomes slightly more tricky when preparers and legacy tests use the same functions to register build components and define default modules. This change splits the RegisterRequiredBuildComponentsForTest and GatherRequiredDepsForTest methods into two methods each, with the existing method used for legacy tests and calling the new method that is used for the preparer. At the moment all the functionality is in the new methods but over time, as functionality is extracted into separate preparers, the functionality can also be moved from the method that is common to both legacy and fixture based tests into the legacy only method. Bug: 177892522 Test: m nothing Change-Id: I233a4fe1fb072a00292acc2bb20821ec82a9bd67
Diffstat (limited to 'java/testing.go')
-rw-r--r--java/testing.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/java/testing.go b/java/testing.go
index 82a2103fd..d5be5b8db 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -43,7 +43,7 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers(
// Make sure that mutators and module types, e.g. prebuilt mutators available.
android.PrepareForTestWithAndroidBuildComponents,
// Make java build components available to the test.
- android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
+ android.FixtureRegisterWithContext(registerRequiredBuildComponentsForTest),
android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
)
@@ -52,7 +52,7 @@ var PrepareForTestWithJavaDefaultModules = android.GroupFixturePreparers(
// Make sure that all the module types used in the defaults are registered.
PrepareForTestWithJavaBuildComponents,
// The java default module definitions.
- android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", GatherRequiredDepsForTest()),
+ android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()),
)
var PrepareForTestWithOverlayBuildComponents = android.FixtureRegisterWithContext(registerOverlayBuildComponents)
@@ -178,7 +178,19 @@ func prebuiltApisFilesForLibs(apiLevels []string, sdkLibs []string) map[string][
//
// In particular this must register all the components that are used in the `Android.bp` snippet
// returned by GatherRequiredDepsForTest()
+//
+// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaBuildComponents
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
+ registerRequiredBuildComponentsForTest(ctx)
+}
+
+// registerRequiredBuildComponentsForTest registers the build components used by
+// PrepareForTestWithJavaDefaultModules.
+//
+// As functionality is moved out of here into separate FixturePreparer instances they should also
+// be moved into GatherRequiredDepsForTest for use by tests that have not yet switched to use test
+// fixtures.
+func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
RegisterAARBuildComponents(ctx)
RegisterAppBuildComponents(ctx)
RegisterAppImportBuildComponents(ctx)
@@ -201,7 +213,19 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
// Gather the module definitions needed by tests that depend upon code from this package.
//
// Returns an `Android.bp` snippet that defines the modules that are needed by this package.
+//
+// deprecated: Use test fixtures instead, e.g. PrepareForTestWithJavaDefaultModules
func GatherRequiredDepsForTest() string {
+ return gatherRequiredDepsForTest()
+}
+
+// gatherRequiredDepsForTest gathers the module definitions used by
+// PrepareForTestWithJavaDefaultModules.
+//
+// As functionality is moved out of here into separate FixturePreparer instances they should also
+// be moved into GatherRequiredDepsForTest for use by tests that have not yet switched to use test
+// fixtures.
+func gatherRequiredDepsForTest() string {
var bp string
extraModules := []string{