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
715b1bf5
Commit
715b1bf5
authored
4 years ago
by
Vincent Massol
Browse files
Options
Downloads
Patches
Plain Diff
[Misc] Convert test to JUnit5
parent
35fdf17c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/HibernateStoreTest.java
+29
-29
29 additions, 29 deletions
...src/test/java/com/xpn/xwiki/store/HibernateStoreTest.java
with
29 additions
and
29 deletions
xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/store/HibernateStoreTest.java
+
29
−
29
View file @
715b1bf5
...
...
@@ -23,43 +23,45 @@
import
org.hibernate.HibernateException
;
import
org.hibernate.Transaction
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.xwiki.component.manager.ComponentLookupException
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.Mock
;
import
org.xwiki.context.Execution
;
import
org.xwiki.context.ExecutionContext
;
import
org.xwiki.test.mockito.MockitoComponentMockingRule
;
import
org.xwiki.test.junit5.mockito.ComponentTest
;
import
org.xwiki.test.junit5.mockito.InjectMockComponents
;
import
org.xwiki.test.junit5.mockito.MockComponent
;
import
com.xpn.xwiki.internal.store.hibernate.HibernateStore
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
jupiter
.
api
.
Assert
ions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
HibernateStoreTest
@ComponentTest
class
HibernateStoreTest
{
@Rule
public
MockitoComponentMockingRule
<
HibernateStore
>
mocker
=
new
MockitoComponentMockingRule
<
HibernateStore
>(
HibernateStore
.
class
);
@InjectMockComponents
private
HibernateStore
store
;
private
Transaction
transaction
=
mock
(
Transaction
.
class
);
@MockComponent
private
Execution
execution
;
@Before
public
void
before
()
throws
ComponentLookupException
@Mock
private
Transaction
transaction
;
@BeforeEach
void
before
()
{
ExecutionContext
executionContext
=
mock
(
ExecutionContext
.
class
);
Execution
execution
=
this
.
mocker
.
getInstance
(
Execution
.
class
);
when
(
execution
.
getContext
()).
thenReturn
(
executionContext
);
when
(
executionContext
.
getProperty
(
"hibtransaction"
)).
thenReturn
(
transaction
);
when
(
this
.
execution
.
getContext
()).
thenReturn
(
executionContext
);
when
(
executionContext
.
getProperty
(
"hibtransaction"
)).
thenReturn
(
this
.
transaction
);
}
@Test
public
void
testE
ndTransactionWhenSQLBatchUpdateExceptionThrown
()
throws
Exception
void
e
ndTransactionWhenSQLBatchUpdateExceptionThrown
()
{
SQLException
sqlException2
=
new
SQLException
(
"sqlexception2"
);
sqlException2
.
setNextException
(
new
SQLException
(
"nextexception2"
));
...
...
@@ -68,15 +70,13 @@ public void testEndTransactionWhenSQLBatchUpdateExceptionThrown() throws Excepti
sqlException1
.
initCause
(
sqlException2
);
sqlException1
.
setNextException
(
new
SQLException
(
"nextexception1"
));
doThrow
(
new
HibernateException
(
"exception1"
,
sqlException1
)).
when
(
transaction
).
commit
();
doThrow
(
new
HibernateException
(
"exception1"
,
sqlException1
)).
when
(
this
.
transaction
).
commit
();
try
{
mocker
.
getComponentUnderTest
().
endTransaction
(
true
);
fail
(
"Should have thrown an exception here"
);
}
catch
(
HibernateException
e
)
{
assertEquals
(
"Failed to commit or rollback transaction. Root cause [\n"
+
"SQL next exception = [java.sql.SQLException: nextexception1]\n"
+
"SQL next exception = [java.sql.SQLException: nextexception2]]"
,
e
.
getMessage
());
}
Throwable
exception
=
assertThrows
(
HibernateException
.
class
,
()
->
{
this
.
store
.
endTransaction
(
true
);
});
assertEquals
(
"Failed to commit or rollback transaction. Root cause [\n"
+
"SQL next exception = [java.sql.SQLException: nextexception1]\n"
+
"SQL next exception = [java.sql.SQLException: nextexception2]]"
,
exception
.
getMessage
());
}
}
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