aboutsummaryrefslogtreecommitdiff
path: root/java/dagger/hilt/android/testing/UninstallModules.java
blob: 607d76a68c546f051524b7c835a10c0206c49251 (plain)
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
/*
 * Copyright (C) 2020 The Dagger Authors.
 *
 * 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 dagger.hilt.android.testing;

import dagger.hilt.GeneratesRootInput;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

/**
 * An annotation used to uninstall modules that have previously been installed with {@link
 * dagger.hilt.InstallIn}.
 *
 * <p>This feature should only be used in tests. It is useful for replacing production bindings with
 * fake bindings. The basic idea is to allow users to uninstall the module that provided the
 * production binding so that a fake binding can be provided by the test.
 *
 * <p>Example:
 *
 * <pre><code>
 *   {@literal @}HiltAndroidTest
 *   {@literal @}UninstallModules({
 *       ProdFooModule.class,
 *   })
 *   public class MyTest {
 *     {@literal @}Module
 *     {@literal @}InstallIn(SingletonComponent.class)
 *     interface FakeFooModule {
 *       {@literal @}Binds Foo bindFoo(FakeFoo fakeFoo);
 *     }
 *   }
 * </code></pre>
 */
@GeneratesRootInput
@Target({ElementType.TYPE})
public @interface UninstallModules {

  /**
   * Returns the list of classes to uninstall.
   *
   * <p>These classes must be annotated with both {@link dagger.Module} and {@link
   * dagger.hilt.InstallIn}.
   *
   * <p>Note:A module that is included as part of another module's {@link dagger.Module#includes()}
   * cannot be truly uninstalled until the including module is also uninstalled.
   */
  Class<?>[] value() default {};
}