• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Dagger Authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package dagger.hilt.android;
18 
19 /**
20  * Utility methods for tests that verify which generated component is used to inject the test class.
21  */
22 public abstract class UsesComponentHelper {
23 
defaultComponentName()24   public static String defaultComponentName() {
25     return "dagger.hilt.android.internal.testing.root.DaggerDefault_HiltComponents_SingletonC";
26   }
27 
28   /**
29    * Returns the name of a component that cannot use the default component. Does not handle deduping
30    * if test class names clash.
31    */
perTestComponentName(Object testInstance)32   public static String perTestComponentName(Object testInstance) {
33     return "dagger.hilt.android.internal.testing.root.Dagger"
34         + testInstance.getClass().getSimpleName()
35         + "_HiltComponents_SingletonC";
36   }
37 
38   /**
39    * Returns the name of a component that cannot use the default component, including the expected
40    * prefix applied by Hilt to dedupe clashing class names.
41    */
perTestComponentNameWithDedupePrefix( String expectedPrefix, Object testInstance)42   public static String perTestComponentNameWithDedupePrefix(
43       String expectedPrefix, Object testInstance) {
44     return "dagger.hilt.android.internal.testing.root.Dagger"
45         + expectedPrefix
46         + testInstance.getClass().getSimpleName()
47         + "_HiltComponents_SingletonC";
48   }
49 
UsesComponentHelper()50   private UsesComponentHelper() {}
51 }
52