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.Restore;
19:
20: import static java.lang.annotation.ElementType.FIELD;
21: import java.lang.annotation.Retention;
22: import static java.lang.annotation.RetentionPolicy.RUNTIME;
23: import java.lang.annotation.Target;
24:
25: /**
26: * Annotation indicating that the the {@link org.unitils.inject.InjectModule} should try to inject the object assigned to
27: * the annotated field to a static property of the class defined by the target attribute.
28: * <p/>
29: * Explicit injection is used, which means that the object is injected to the property indicated by the {@link #property()}
30: * attribute.
31: * <p/>
32: * You can also specify what action needs to be performed after the test. Suppose, for example, that you want to
33: * mock a singleton instance by injecting the mock into the static <code>singleton</code> variable. After the test
34: * was performed, you typically want to restore the old (real) singleton value, so that the next test can run with
35: * the normal instance. This can be done by setting the resetType to the OLD_VALUE value. You can also specify that
36: * the static instance should be cleared by setting it to null (or 0) or just leave the injected value.
37: *
38: * @author Filip Neven
39: * @author Tim Ducheyne
40: */
41: @Target(FIELD)
42: @Retention(RUNTIME)
43: public @interface InjectIntoStatic {
44:
45: /**
46: * The target class to which the object referenced by the annotated field is injected
47: *
48: * @return the target class, null for tested object
49: */
50: Class<?> target();
51:
52: /**
53: * OGNL expression that defines the property to which the object referenced by the annotated fiel is injected
54: *
55: * @return the ognl expression, not null
56: */
57: String property();
58:
59: /**
60: * The action that needs to be performed after the test was performed. Should the old value be put back,
61: * should it be set to a java default value (null) or should nothing be done.
62: *
63: * @return the reset type, not null
64: */
65: Restore restore() default Restore.DEFAULT;
66:
67: }
|