Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xwiki-platform
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XWiki
xwiki-platform
Commits
73a637b9
Commit
73a637b9
authored
2 days ago
by
Vincent Massol
Browse files
Options
Downloads
Patches
Plain Diff
[Misc] Migrate test to JUnit5
parent
d3ade07e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/test/java/org/xwiki/icon/internal/IconThemeListenerTest.java
+23
-30
23 additions, 30 deletions
...t/java/org/xwiki/icon/internal/IconThemeListenerTest.java
with
23 additions
and
30 deletions
xwiki-platform-core/xwiki-platform-icon/xwiki-platform-icon-default/src/test/java/org/xwiki/icon/internal/IconThemeListenerTest.java
+
23
−
30
View file @
73a637b9
...
...
@@ -22,23 +22,22 @@
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.jupiter.api.Test
;
import
org.xwiki.bridge.event.DocumentDeletedEvent
;
import
org.xwiki.bridge.event.DocumentUpdatedEvent
;
import
org.xwiki.component.manager.ComponentLookupException
;
import
org.xwiki.icon.IconSetCache
;
import
org.xwiki.model.reference.DocumentReference
;
import
org.xwiki.model.reference.LocalDocumentReference
;
import
org.xwiki.test.
mockito.M
ockitoComponent
MockingRule
;
import
org.xwiki.test.
junit5.m
ockito
.
Component
Test
;
import
org.xwiki.observation.event.Event
;
import
org.xwiki.test.junit5.mockito.InjectMockComponents
;
import
org.xwiki.test.junit5.mockito.MockComponent
;
import
com.xpn.xwiki.doc.XWikiDocument
;
import
com.xpn.xwiki.objects.BaseObject
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assert
ions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assert
ions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
atLeastOnce
;
...
...
@@ -53,26 +52,21 @@
* @since 6.2M1
* @version $Id$
*/
public
class
IconThemeListenerTest
@ComponentTest
class
IconThemeListenerTest
{
@Rule
public
MockitoComponentMockingRule
<
IconThemeListener
>
mocker
=
new
MockitoComponentMockingRule
<>(
IconThemeListener
.
class
);
@InjectMockComponents
private
IconThemeListener
listener
;
@MockComponent
private
IconSetCache
iconSetCache
;
@Before
public
void
setUp
()
throws
ComponentLookupException
{
iconSetCache
=
mocker
.
getInstance
(
IconSetCache
.
class
);
}
@Test
public
void
onEvent
()
throws
Exception
void
onEvent
()
{
// Mocks
XWikiDocument
doc
=
mock
(
XWikiDocument
.
class
);
List
<
BaseObject
>
list
=
new
ArrayList
<
BaseObject
>();
List
<
BaseObject
>
list
=
new
ArrayList
<>();
BaseObject
obj
=
mock
(
BaseObject
.
class
);
list
.
add
(
obj
);
when
(
obj
.
getStringValue
(
"name"
)).
thenReturn
(
"icontheme1"
);
...
...
@@ -84,7 +78,7 @@ public void onEvent() throws Exception
when
(
doc
.
getXObjects
(
eq
(
iconThemeClassRef
))).
thenReturn
(
list
);
// Tests
mocker
.
getComponentUnderTest
()
.
onEvent
(
null
,
doc
,
null
);
this
.
listener
.
onEvent
(
null
,
doc
,
null
);
// Verify
verify
(
iconSetCache
,
atLeastOnce
()).
clear
(
docRef
);
...
...
@@ -92,40 +86,40 @@ public void onEvent() throws Exception
}
@Test
public
void
onEventWhenNoObjects
()
throws
Exception
void
onEventWhenNoObjects
()
{
// Mocks
XWikiDocument
doc
=
mock
(
XWikiDocument
.
class
);
when
(
doc
.
getXObject
(
any
(
DocumentReference
.
class
))).
thenReturn
(
null
);
// Tests
mocker
.
getComponentUnderTest
()
.
onEvent
(
null
,
doc
,
null
);
this
.
listener
.
onEvent
(
null
,
doc
,
null
);
// Verify
verify
(
iconSetCache
,
never
()).
clear
(
any
(
DocumentReference
.
class
));
}
@Test
public
void
onEventWhenEmptyListObjects
()
throws
Exception
void
onEventWhenEmptyListObjects
()
{
// Mocks
XWikiDocument
doc
=
mock
(
XWikiDocument
.
class
);
List
<
BaseObject
>
list
=
new
ArrayList
<
BaseObject
>();
List
<
BaseObject
>
list
=
new
ArrayList
<>();
LocalDocumentReference
iconThemeClassRef
=
new
LocalDocumentReference
(
"IconThemesCode"
,
"IconThemeClass"
);
when
(
doc
.
getXObjects
(
eq
(
iconThemeClassRef
))).
thenReturn
(
list
);
// Tests
mocker
.
getComponentUnderTest
()
.
onEvent
(
null
,
doc
,
null
);
this
.
listener
.
onEvent
(
null
,
doc
,
null
);
// Verify
verify
(
iconSetCache
,
never
()).
clear
(
any
(
DocumentReference
.
class
));
}
@Test
public
void
getEvents
()
throws
Exception
void
getEvents
()
{
List
<
Event
>
results
=
mocker
.
getComponentUnderTest
()
.
getEvents
();
List
<
Event
>
results
=
this
.
listener
.
getEvents
();
// Verify
assertEquals
(
2
,
results
.
size
());
...
...
@@ -134,9 +128,8 @@ public void getEvents() throws Exception
}
@Test
public
void
getName
()
throws
Exception
void
getName
()
{
assertEquals
(
"Icon Theme listener."
,
mocker
.
getComponentUnderTest
()
.
getName
());
assertEquals
(
"Icon Theme listener."
,
this
.
listener
.
getName
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment