1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro.rss; |
21 |
|
|
22 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
23 |
|
import org.xwiki.rendering.macro.rss.RssMacroParameters; |
24 |
|
import org.jmock.Mockery; |
25 |
|
import org.jmock.Expectations; |
26 |
|
import org.junit.Test; |
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Assert; |
29 |
|
|
30 |
|
|
31 |
|
@link |
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 94.4% |
Uncovered Elements: 1 (18) |
Complexity: 5 |
Complexity Density: 0.36 |
|
36 |
|
public class RssMacroTest |
37 |
|
{ |
38 |
|
private RssMacro macro; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
2 |
@Before... |
41 |
|
public void setUp() |
42 |
|
{ |
43 |
2 |
this.macro = new RssMacro(); |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
50 |
1 |
@Test... |
51 |
|
public void testRequiredParameterMissing() throws Exception |
52 |
|
{ |
53 |
1 |
try { |
54 |
1 |
this.macro.execute(new RssMacroParameters(), null, null); |
55 |
0 |
Assert.fail("Should have thrown an exception"); |
56 |
|
} catch (MacroExecutionException expected) { |
57 |
1 |
Assert.assertEquals("The required 'feed' parameter is missing", expected.getMessage()); |
58 |
|
} |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
64 |
1 |
@Test(expected = MacroExecutionException.class)... |
65 |
|
public void testInvalidDocument() throws Exception |
66 |
|
{ |
67 |
|
|
68 |
1 |
Mockery context = new Mockery(); |
69 |
1 |
final RomeFeedFactory mockFactory = context.mock(RomeFeedFactory.class); |
70 |
1 |
final RssMacroParameters parameters = new RssMacroParameters(); |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
71 |
1 |
context.checking(new Expectations() {{... |
72 |
1 |
oneOf(mockFactory).createFeed(with(same(parameters))); will(throwException( |
73 |
|
new MacroExecutionException("Error"))); |
74 |
|
}}); |
75 |
1 |
this.macro.setFeedFactory(mockFactory); |
76 |
|
|
77 |
|
|
78 |
1 |
parameters.setFeed("http://www.xwiki.org"); |
79 |
|
|
80 |
1 |
this.macro.execute(parameters, null, null); |
81 |
|
} |
82 |
|
} |