aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java')
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java
index 2c852fd5c..9b45c3b53 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/util/JPAUtilsTest.java
@@ -21,24 +21,27 @@
package org.onap.policy.pap.xacml.rest.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
-import org.junit.Rule;
+import javax.persistence.Query;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
public class JPAUtilsTest {
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void testJPAUtils() throws IllegalAccessException {
- EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
- JPAUtils utils = JPAUtils.getJPAUtilsInstance(emf);
-
- assertEquals(utils.dbLockdownIgnoreErrors(), false);
-
- thrown.expect(NullPointerException.class);
- utils.dbLockdown();
- }
+ @Test(expected = IllegalAccessException.class)
+ public void testJPAUtils() throws IllegalAccessException {
+ // Setup test data
+ EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
+ EntityManager em = Mockito.mock(EntityManager.class);
+ Query query = Mockito.mock(Query.class);
+ Mockito.when(emf.createEntityManager()).thenReturn(em);
+ Mockito.when(em.createNamedQuery(Mockito.any())).thenReturn(query);
+
+ // Test lockdown
+ JPAUtils utils = JPAUtils.getJPAUtilsInstance(emf);
+ assertEquals(utils.dbLockdownIgnoreErrors(), false);
+ utils.dbLockdown();
+ fail("Expecting an exception");
+ }
}