1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.dependencyfinder.webwork; |
34 |
| |
35 |
| import java.io.*; |
36 |
| import java.util.*; |
37 |
| |
38 |
| import com.opensymphony.xwork.*; |
39 |
| import static org.hamcrest.Matchers.*; |
40 |
| import static org.jmock.Expectations.*; |
41 |
| import org.jmock.*; |
42 |
| import org.jmock.integration.junit4.*; |
43 |
| import static org.junit.Assert.*; |
44 |
| import org.junit.*; |
45 |
| import org.junit.runner.*; |
46 |
| |
47 |
| import com.jeantessier.classreader.*; |
48 |
| import com.jeantessier.dependency.*; |
49 |
| |
50 |
| @RunWith(JMock.class) |
51 |
| public class TestExtractAction { |
52 |
| private Mockery context; |
53 |
| |
54 |
| private Map<String, Object> application; |
55 |
| |
56 |
| private ExtractAction sut; |
57 |
| |
58 |
4
| @Before
|
59 |
| public void setUp() throws Exception { |
60 |
4
| context = new Mockery();
|
61 |
| |
62 |
4
| application = new HashMap<String, Object>();
|
63 |
4
| application.put("source", "classes" + File.separator + "test.class");
|
64 |
| |
65 |
4
| sut = new ExtractAction();
|
66 |
| } |
67 |
| |
68 |
1
| @Test
|
69 |
| public void testExecute() throws Exception { |
70 |
1
| sut.setApplication(application);
|
71 |
1
| String result = sut.execute();
|
72 |
| |
73 |
1
| assertThat("Result", result, is(equal(Action.INPUT)));
|
74 |
1
| assertThat("Unexpected dispatcher", (ClassfileLoaderDispatcher) application.get("dispatcher"), is(aNull(ClassfileLoaderDispatcher.class)));
|
75 |
1
| assertThat("Unexpected factory", (NodeFactory) application.get("factory"), is(aNull(NodeFactory.class)));
|
76 |
1
| assertThat("Unexpected monitor", (Monitor) application.get("monitor"), is(aNull(Monitor.class)));
|
77 |
1
| assertThat("Unexpected start", (Date) sut.getStart(), is(aNull(Date.class)));
|
78 |
1
| assertThat("Unexpected stop", (Date) sut.getStop(), is(aNull(Date.class)));
|
79 |
| } |
80 |
| |
81 |
1
| @Test
|
82 |
| public void testFirstExtract() { |
83 |
1
| sut.setApplication(application);
|
84 |
1
| String result = sut.doExtract();
|
85 |
| |
86 |
1
| assertThat("Result", result, is(equal(Action.SUCCESS)));
|
87 |
1
| assertThat("Missing dispatcher", (ClassfileLoaderDispatcher) application.get("dispatcher"), is(aNonNull(ClassfileLoaderDispatcher.class)));
|
88 |
1
| assertThat("Missing factory", (NodeFactory) application.get("factory"), is(aNonNull(NodeFactory.class)));
|
89 |
1
| assertThat("Missing monitor", (Monitor) application.get("monitor"), is(aNonNull(Monitor.class)));
|
90 |
| } |
91 |
| |
92 |
1
| @Test
|
93 |
| public void testSecondExtract() { |
94 |
1
| ClassfileLoaderDispatcher dispatcher = new ModifiedOnlyDispatcher(ClassfileLoaderEventSource.DEFAULT_DISPATCHER);
|
95 |
1
| NodeFactory factory = new NodeFactory();
|
96 |
1
| CodeDependencyCollector collector = new CodeDependencyCollector(factory);
|
97 |
1
| DeletingVisitor deletingVisitor = new DeletingVisitor(factory);
|
98 |
1
| Monitor monitor = new Monitor(collector, deletingVisitor);
|
99 |
| |
100 |
1
| application.put("dispatcher", dispatcher);
|
101 |
1
| application.put("factory", factory);
|
102 |
1
| application.put("monitor", monitor);
|
103 |
| |
104 |
1
| sut.setApplication(application);
|
105 |
1
| String result = sut.doExtract();
|
106 |
| |
107 |
1
| assertThat("Result", result, is(equal(Action.SUCCESS)));
|
108 |
1
| assertThat("Dispatcher", (ClassfileLoaderDispatcher) application.get("dispatcher"), is(not(same(dispatcher))));
|
109 |
1
| assertThat("Factory", (NodeFactory) application.get("factory"), is(not(same(factory))));
|
110 |
1
| assertThat("Monitor", (Monitor) application.get("monitor"), is(not(same(monitor))));
|
111 |
| } |
112 |
| |
113 |
1
| @Test
|
114 |
| public void testUpdate() { |
115 |
1
| ClassfileLoaderDispatcher dispatcher = new ModifiedOnlyDispatcher(ClassfileLoaderEventSource.DEFAULT_DISPATCHER);
|
116 |
1
| NodeFactory factory = new NodeFactory();
|
117 |
1
| CodeDependencyCollector collector = new CodeDependencyCollector(factory);
|
118 |
1
| DeletingVisitor deletingVisitor = new DeletingVisitor(factory);
|
119 |
1
| Monitor monitor = new Monitor(collector, deletingVisitor);
|
120 |
| |
121 |
1
| application.put("dispatcher", dispatcher);
|
122 |
1
| application.put("factory", factory);
|
123 |
1
| application.put("monitor", monitor);
|
124 |
| |
125 |
1
| sut.setApplication(application);
|
126 |
1
| String result = sut.doUpdate();
|
127 |
| |
128 |
1
| assertThat("Result", result, is(equal(Action.SUCCESS)));
|
129 |
1
| assertThat("Dispatcher", (ClassfileLoaderDispatcher) application.get("dispatcher"), is(same(dispatcher)));
|
130 |
1
| assertThat("Factory", (NodeFactory) application.get("factory"), is(same(factory)));
|
131 |
1
| assertThat("Monitor", (Monitor) application.get("monitor"), is(same(monitor)));
|
132 |
| } |
133 |
| } |