Merge "BUG 1853 : Clustered Data Store causes Out of Memory"
[controller.git] / opendaylight / netconf / netconf-util / src / test / java / org / opendaylight / controller / netconf / util / CloseableUtilTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.util;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.fail;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.mock;
15
16 import com.google.common.collect.Lists;
17 import org.junit.Test;
18
19 public class CloseableUtilTest {
20
21     @Test
22     public void testCloseAllFail() throws Exception {
23         final AutoCloseable failingCloseable = new AutoCloseable() {
24             @Override
25             public void close() throws Exception {
26                 throw new RuntimeException("testing failing close");
27             }
28         };
29
30         try {
31             CloseableUtil.closeAll(Lists.newArrayList(failingCloseable, failingCloseable));
32             fail("Exception with suppressed should be thrown");
33         } catch (final RuntimeException e) {
34             assertEquals(1, e.getSuppressed().length);
35         }
36     }
37
38     @Test
39     public void testCloseAll() throws Exception {
40         final AutoCloseable failingCloseable = mock(AutoCloseable.class);
41         doNothing().when(failingCloseable).close();
42         CloseableUtil.closeAll(Lists.newArrayList(failingCloseable, failingCloseable));
43     }
44 }