1 /* 2 * Copyright (C) 2020 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.testing; 18 19 import java.lang.annotation.ElementType; 20 import java.lang.annotation.Target; 21 22 /** 23 * An annotation used to uninstall modules that have previously been installed with {@link 24 * dagger.hilt.InstallIn}. 25 * 26 * <p>This feature should only be used in tests. It is useful for replacing production bindings with 27 * fake bindings. The basic idea is to allow users to uninstall the module that provided the 28 * production binding so that a fake binding can be provided by the test. 29 * 30 * <p>Example: 31 * 32 * <pre><code> 33 * {@literal @}HiltAndroidTest 34 * {@literal @}UninstallModules({ 35 * ProdFooModule.class, 36 * }) 37 * public class MyTest { 38 * {@literal @}Module 39 * {@literal @}InstallIn(SingletonComponent.class) 40 * interface FakeFooModule { 41 * {@literal @}Binds Foo bindFoo(FakeFoo fakeFoo); 42 * } 43 * } 44 * </code></pre> 45 */ 46 @Target({ElementType.TYPE}) 47 public @interface UninstallModules { 48 49 /** 50 * Returns the list of classes to uninstall. 51 * 52 * <p>These classes must be annotated with both {@link dagger.Module} and {@link 53 * dagger.hilt.InstallIn}. 54 * 55 * <p>Note:A module that is included as part of another module's {@link dagger.Module#includes()} 56 * cannot be truly uninstalled until the including module is also uninstalled. 57 */ value()58 Class<?>[] value() default {}; 59 } 60