21
21
22
22
import java .net .URL ;
23
23
24
- import org .junit .Before ;
25
- import org .junit .Rule ;
26
- import org .junit .Test ;
24
+ import org .junit .jupiter .api .BeforeEach ;
25
+ import org .junit .jupiter .api .Test ;
27
26
import org .xwiki .context .Execution ;
28
27
import org .xwiki .context .ExecutionContext ;
29
28
import org .xwiki .model .reference .WikiReference ;
30
- import org .xwiki .test .mockito .MockitoComponentMockingRule ;
29
+ import org .xwiki .test .junit5 .mockito .ComponentTest ;
30
+ import org .xwiki .test .junit5 .mockito .InjectMockComponents ;
31
+ import org .xwiki .test .junit5 .mockito .MockComponent ;
31
32
import org .xwiki .url .ExtendedURL ;
32
33
import org .xwiki .wiki .descriptor .WikiDescriptor ;
33
34
import org .xwiki .wiki .descriptor .WikiDescriptorManager ;
34
35
35
- import static org .junit .Assert .assertEquals ;
36
+ import static org .junit .jupiter . api . Assertions .assertEquals ;
36
37
import static org .mockito .Mockito .*;
37
38
38
39
/**
41
42
* @version $Id$
42
43
* @since 6.3M1
43
44
*/
44
- public class PathWikiReferenceExtractorTest
45
+ @ ComponentTest
46
+ class PathWikiReferenceExtractorTest
45
47
{
46
- @ Rule
47
- public MockitoComponentMockingRule <PathWikiReferenceExtractor > mocker =
48
- new MockitoComponentMockingRule <>(PathWikiReferenceExtractor .class );
48
+ @ InjectMockComponents
49
+ private PathWikiReferenceExtractor extractor ;
49
50
51
+ @ MockComponent
50
52
private WikiDescriptorManager wikiDescriptorManager ;
51
53
52
- @ Before
53
- public void setUp () throws Exception
54
+ @ MockComponent
55
+ private Execution execution ;
56
+
57
+ @ MockComponent
58
+ private StandardURLConfiguration urlConfiguration ;
59
+
60
+ @ BeforeEach
61
+ void setUp () throws Exception
54
62
{
55
- this .wikiDescriptorManager = mocker .getInstance (WikiDescriptorManager .class );
56
- when (wikiDescriptorManager .getMainWikiId ()).thenReturn ("xwiki" );
63
+ when (this .wikiDescriptorManager .getMainWikiId ()).thenReturn ("xwiki" );
57
64
}
58
65
59
66
@ Test
60
- public void extractWhenWikiDescriptor () throws Exception
67
+ void extractWhenWikiDescriptor () throws Exception
61
68
{
62
69
setUpConfiguration (WikiNotFoundBehavior .REDIRECT_TO_MAIN_WIKI );
63
70
64
- WikiDescriptorManager wikiDescriptorManager = mocker .getInstance (WikiDescriptorManager .class );
65
- when (wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (new WikiDescriptor ("wikiid" , "someWiki" ));
71
+ when (this .wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (new WikiDescriptor ("wikiid" , "someWiki" ));
66
72
67
73
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "wikiid" );
68
74
}
69
75
70
76
@ Test
71
- public void extractWhenNoWikiDescriptor () throws Exception
77
+ void extractWhenNoWikiDescriptor () throws Exception
72
78
{
73
79
setUpConfiguration (WikiNotFoundBehavior .REDIRECT_TO_MAIN_WIKI );
74
80
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "xwiki" );
75
81
}
76
82
77
83
@ Test
78
- public void extractWhenWikiDescriptorButEmptyServerName () throws Exception
84
+ void extractWhenWikiDescriptorButEmptyServerName () throws Exception
79
85
{
80
86
setUpConfiguration (WikiNotFoundBehavior .REDIRECT_TO_MAIN_WIKI );
81
87
82
- WikiDescriptorManager wikiDescriptorManager = mocker .getInstance (WikiDescriptorManager .class );
83
- when (wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (new WikiDescriptor ("" , "someWiki" ));
88
+ when (this .wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (new WikiDescriptor ("" , "someWiki" ));
84
89
85
90
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "xwiki" );
86
91
}
87
92
88
93
@ Test
89
- public void extractWhenNoDescriptorMatchingAliasButDescriptorMatchingId () throws Exception
94
+ void extractWhenNoDescriptorMatchingAliasButDescriptorMatchingId () throws Exception
90
95
{
91
96
setUpConfiguration (WikiNotFoundBehavior .REDIRECT_TO_MAIN_WIKI );
92
97
93
- WikiDescriptorManager wikiDescriptorManager = mocker .getInstance (WikiDescriptorManager .class );
94
- when (wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (null );
95
- when (wikiDescriptorManager .getById ("someWiki" )).thenReturn (new WikiDescriptor ("dummy" , "dummy" ));
98
+ when (this .wikiDescriptorManager .getByAlias ("someWiki" )).thenReturn (null );
99
+ when (this .wikiDescriptorManager .getById ("someWiki" )).thenReturn (new WikiDescriptor ("dummy" , "dummy" ));
96
100
97
101
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "somewiki" );
98
102
}
99
103
100
104
@ Test
101
- public void extractWhenNoWikiDescriptorButWithDomainBasedURL () throws Exception
105
+ void extractWhenNoWikiDescriptorButWithDomainBasedURL () throws Exception
102
106
{
103
107
setUpConfiguration (WikiNotFoundBehavior .REDIRECT_TO_MAIN_WIKI );
104
108
testAndAssert ("http://wiki.server.com/xwiki/bin/view/Main/WebHome" , "xwiki" );
105
109
}
106
110
107
111
@ Test
108
- public void extractWhenNoWikiDescriptorAndDisplayErrorWhenWikiNotFound () throws Exception
112
+ void extractWhenNoWikiDescriptorAndDisplayErrorWhenWikiNotFound () throws Exception
109
113
{
110
114
setUpConfiguration (WikiNotFoundBehavior .DISPLAY_ERROR );
111
115
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "somewiki" );
112
116
}
113
117
114
118
@ Test
115
- public void extractWhenNoExecutionContext () throws Exception
119
+ void extractWhenNoExecutionContext () throws Exception
116
120
{
117
121
testAndAssert ("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome" , "somewiki" );
118
122
@@ -125,19 +129,16 @@ private void testAndAssert(String urlToTest, String expectedWikiId) throws Excep
125
129
ExtendedURL url = new ExtendedURL (new URL (urlToTest ), "xwiki" );
126
130
// Remove the resource type (i.e. the first segment) since this is what is expected by the extractor
127
131
url .getSegments ().remove (0 );
128
- WikiReference wikiReference = this .mocker . getComponentUnderTest () .extract (url );
132
+ WikiReference wikiReference = this .extractor .extract (url );
129
133
assertEquals (new WikiReference (expectedWikiId ), wikiReference );
130
134
}
131
135
132
- private void setUpConfiguration (WikiNotFoundBehavior wikiNotFoundBehavior ) throws Exception
136
+ private void setUpConfiguration (WikiNotFoundBehavior wikiNotFoundBehavior )
133
137
{
134
138
// Simulate a configured Execution Context
135
- Execution execution = mocker .getInstance (Execution .class );
136
139
ExecutionContext executionContext = new ExecutionContext ();
137
140
executionContext .setProperty ("xwikicontext" , true );
138
- when (execution .getContext ()).thenReturn (executionContext );
139
-
140
- StandardURLConfiguration urlConfiguration = mocker .getInstance (StandardURLConfiguration .class );
141
- when (urlConfiguration .getWikiNotFoundBehavior ()).thenReturn (wikiNotFoundBehavior );
141
+ when (this .execution .getContext ()).thenReturn (executionContext );
142
+ when (this .urlConfiguration .getWikiNotFoundBehavior ()).thenReturn (wikiNotFoundBehavior );
142
143
}
143
144
}
0 commit comments