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