2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.util;
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;
15 import java.util.List;
16 import org.junit.Test;
18 public class CloseableUtilTest {
20 public void testCloseAllFail() {
21 final AutoCloseable failingCloseable = () -> {
22 throw new RuntimeException("testing failing close");
25 final RuntimeException ex = assertThrows(RuntimeException.class,
26 () -> CloseableUtil.closeAll(List.of(failingCloseable, failingCloseable)));
27 assertEquals(1, ex.getSuppressed().length);
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));