Move netconf-dom-api
[netconf.git] / protocol / netconf-util / src / test / java / org / opendaylight / 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 package org.opendaylight.netconf.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.mock;
14
15 import java.util.List;
16 import org.junit.Test;
17
18 public class CloseableUtilTest {
19     @Test
20     public void testCloseAllFail() {
21         final AutoCloseable failingCloseable = () -> {
22             throw new RuntimeException("testing failing close");
23         };
24
25         final RuntimeException ex = assertThrows(RuntimeException.class,
26             () -> CloseableUtil.closeAll(List.of(failingCloseable, failingCloseable)));
27         assertEquals(1, ex.getSuppressed().length);
28     }
29
30     @Test
31     public void testCloseAll() throws Exception {
32         final AutoCloseable failingCloseable = mock(AutoCloseable.class);
33         doNothing().when(failingCloseable).close();
34         CloseableUtil.closeAll(List.of(failingCloseable, failingCloseable));
35     }
36 }