@Retention(value=RUNTIME) @Target(value=TYPE) @Inherited @Repeatable(value=ExcludeBeanClasses.All.class) public @interface ExcludeBeanClasses
ExcludeBeanClasses excludes a set of classes with bean defining annotations (e.g. scopes) from automatic
discovery. This can be helpful to allow replacing bean classes with a different implementation; typically a mock.
This annotation works as an inverse of AddBeanClasses hence usually requires actual bean implementation
classes as parameters.
NOTE: This annotation will only exclude beans defined by class annotations. It will not exclude beans of the
specified type that are defined by Produces producer methods/fields or synthetic
beans.
Example:
@EnableAutoWeld
@ExcludeBeanClasses(Foo.class) // Excludes Foo bean class from automatic discovery
class TestSomeFoo {
@Inject
SomeFoo someFoo; // SomeFoo depends upon application scoped bean Foo
@Produces
Foo mockFoo = mock(Foo.class); // mockFoo is now produced in place of original Foo impl
@Test
void test(Foo myFoo) {
assertNotNull(myFoo);
assertEquals(myFoo.getBar(), "mock-foo");
}
}
ExcludeBeanpublic abstract Class<?>[] value
Copyright © 2019. All rights reserved.