01: package org.vraptor.plugin;
02:
03: import java.util.Arrays;
04: import java.util.HashSet;
05: import java.util.List;
06:
07: import org.jmock.Mock;
08: import org.vraptor.AbstractTest;
09: import org.vraptor.component.ComponentManager;
10: import org.vraptor.component.ComponentType;
11: import org.vraptor.component.InvalidComponentException;
12: import org.vraptor.component.LogicNotFoundException;
13:
14: public class ComponentWrapperVisitorTest extends AbstractTest {
15:
16: private Mock managerProxy;
17:
18: private ComponentManager manager;
19:
20: private List<ComponentType> components;
21:
22: public void testRegisterRequiredComponents()
23: throws InvalidComponentException, LogicNotFoundException {
24: managerProxy.expects(once()).method("register").with(
25: eq(components.get(0)));
26: ComponentWrapper wrapper = new ComponentWrapper() {
27: public boolean needsToWrap(ComponentType component)
28: throws LogicNotFoundException {
29: return true;
30: }
31:
32: public ComponentType wrap(ComponentType component) {
33: return component;
34: }
35: };
36: ComponentWrapperVisitor visitor = new ComponentWrapperVisitor(
37: wrapper);
38: visitor.visit(manager);
39: }
40:
41: @Override
42: protected void setUp() throws Exception {
43: super .setUp();
44: this .managerProxy = mock(ComponentManager.class);
45: this .components = Arrays
46: .asList(new ComponentType[] { createComponentType(SimpleComponent.class) });
47: managerProxy.expects(once()).method("getComponents").will(
48: returnValue(new HashSet(components)));
49: this .manager = (ComponentManager) managerProxy.proxy();
50: }
51:
52: public static class SimpleComponent {
53:
54: }
55:
56: public void testIgnoresNotRequiredComponents()
57: throws LogicNotFoundException {
58: ComponentWrapper wrapper = new ComponentWrapper() {
59: public boolean needsToWrap(ComponentType component)
60: throws LogicNotFoundException {
61: return false;
62: }
63:
64: public ComponentType wrap(ComponentType component) {
65: return component;
66: }
67: };
68: ComponentWrapperVisitor visitor = new ComponentWrapperVisitor(
69: wrapper);
70: visitor.visit(manager);
71: }
72:
73: }
|