2 * ============LICENSE_START=======================================================
3 * feature-session-persistence
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.persistence;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.never;
25 import static org.mockito.Mockito.verify;
27 import javax.persistence.EntityManager;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.drools.persistence.EntityMgrCloser;
33 public class EntityMgrCloserTest {
35 private EntityManager mgr;
39 public void setUp() throws Exception {
40 mgr = mock(EntityManager.class);
45 * Verifies that the constructor does not do anything extra before
49 public void testEntityMgrCloser() {
50 EntityMgrCloser c = new EntityMgrCloser(mgr);
52 // verify not closed yet
53 verify(mgr, never()).close();
59 * Verifies that the manager gets closed when close() is invoked.
62 public void testClose() {
63 EntityMgrCloser c = new EntityMgrCloser(mgr);
72 * Ensures that the manager gets closed when "try" block exits normally.
75 public void testClose_TryWithoutExcept() {
76 try(EntityMgrCloser c = new EntityMgrCloser(mgr)) {
84 * Ensures that the manager gets closed when "try" block throws an
88 public void testClose_TryWithExcept() {
90 try(EntityMgrCloser c = new EntityMgrCloser(mgr)) {
91 throw new Exception("expected exception");
94 } catch (Exception e) {