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.controller.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 {
22 public void testCloseAllFail() throws Exception {
23 final AutoCloseable failingCloseable = new AutoCloseable() {
25 public void close() throws Exception {
26 throw new RuntimeException("testing failing close");
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);
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));