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
9 package org.opendaylight.netconf.util;
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;
16 import com.google.common.collect.Lists;
17 import org.junit.Test;
19 public class CloseableUtilTest {
21 @SuppressWarnings("checkstyle:IllegalCatch")
23 public void testCloseAllFail() throws Exception {
24 final AutoCloseable failingCloseable = () -> {
25 throw new RuntimeException("testing failing close");
29 CloseableUtil.closeAll(Lists.newArrayList(failingCloseable, failingCloseable));
30 fail("Exception with suppressed should be thrown");
31 } catch (final RuntimeException e) {
32 assertEquals(1, e.getSuppressed().length);
37 public void testCloseAll() throws Exception {
38 final AutoCloseable failingCloseable = mock(AutoCloseable.class);
39 doNothing().when(failingCloseable).close();
40 CloseableUtil.closeAll(Lists.newArrayList(failingCloseable, failingCloseable));