01: package org.vraptor.component;
02:
03: import junit.framework.TestCase;
04:
05: import org.vraptor.annotations.Out;
06: import org.vraptor.reflection.GettingException;
07: import org.vraptor.reflection.MethodInvocationException;
08: import org.vraptor.reflection.ReflectionUtil;
09: import org.vraptor.scope.ScopeType;
10:
11: public class FieldOutjecterTest extends TestCase {
12:
13: public static class FieldOut {
14:
15: @SuppressWarnings("unused")
16: @Out
17: private String val;
18:
19: }
20:
21: public static class CustomFieldOut {
22:
23: @SuppressWarnings("unused")
24: @Out(key="a",scope=ScopeType.SESSION)
25: private String val;
26:
27: }
28:
29: public void testReadsOverridenKey() {
30: FieldOutjecter outjecter = new FieldOutjecter(
31: grabField(CustomFieldOut.class));
32: assertEquals("a", outjecter.getKey());
33: }
34:
35: private FieldAnnotation<Out> grabField(Class type) {
36: return ReflectionUtil.readAnnotations(type, Out.class).get(0);
37: }
38:
39: public void testReadsDefaultKey() {
40: FieldOutjecter outjecter = new FieldOutjecter(
41: grabField(FieldOut.class));
42: assertEquals("val", outjecter.getKey());
43: }
44:
45: public void testReadsOverridenScope() {
46: FieldOutjecter outjecter = new FieldOutjecter(
47: grabField(CustomFieldOut.class));
48: assertEquals(ScopeType.SESSION, outjecter.getScope());
49: }
50:
51: public void testRetrievesTheObject() throws GettingException,
52: MethodInvocationException {
53: FieldOutjecter outjecter = new FieldOutjecter(
54: grabField(FieldOut.class));
55: FieldOut obj = new FieldOut();
56: obj.val = "oi";
57: assertEquals("oi", outjecter.getValue(obj));
58: }
59: }
|