01: /*
02: * Copyright 2006-2007, Unitils.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.unitils.inject.annotation;
17:
18: import org.unitils.inject.util.PropertyAccess;
19: import org.unitils.inject.util.Restore;
20:
21: import static java.lang.annotation.ElementType.FIELD;
22: import java.lang.annotation.Retention;
23: import static java.lang.annotation.RetentionPolicy.RUNTIME;
24: import java.lang.annotation.Target;
25:
26: /**
27: * Annotation indicating that the {@link org.unitils.inject.InjectModule} should try to inject the object assigned to
28: * the annotated field to a static property of the class defined by the target attribute.
29: * <p/>
30: * Automatic injection by type is used, which means that a the object is injected to the most specific static property
31: * with an assignable type.
32: * <p/>
33: * You can also specify what action needs to be performed after the test. Suppose, for example, that you want to
34: * mock a singleton instance by injecting the mock into the static <code>singleton</code> variable. After the test
35: * was performed, you typically want to restore the old (real) singleton value, so that the next test can run with
36: * the normal instance. This can be done by setting the resetType to the OLD_VALUE value. You can also specify that
37: * the static instance should be cleared by setting it to null (or 0) or just leave the injected value.
38: *
39: * @author Filip Neven
40: * @author Tim Ducheyne
41: */
42: @Target(FIELD)
43: @Retention(RUNTIME)
44: public @interface InjectIntoStaticByType {
45:
46: /**
47: * The target class to which the object referenced by the annotated field is injected
48: *
49: * @return the target class, null for tested object
50: */
51: Class<?> target();
52:
53: /**
54: * The property access that is used for injection
55: *
56: * @return the access type, not null
57: */
58: PropertyAccess propertyAccess() default PropertyAccess.DEFAULT;
59:
60: /**
61: * The action that needs to be performed after the test was performed. Should the old value be put back,
62: * should it be set to a java default value (null) or should nothing be done.
63: *
64: * @return the reset type, not null
65: */
66: Restore restore() default Restore.DEFAULT;
67:
68: }
|