2 * Copyright (c) 2014 Robert Varga. 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.yangtools.util.concurrent;
10 import static org.junit.Assert.assertEquals;
12 import java.util.concurrent.ExecutionException;
13 import org.junit.Test;
15 public class ReflectiveExceptionMapperTest {
16 static final class NoArgumentCtorException extends Exception {
17 private static final long serialVersionUID = 1L;
19 NoArgumentCtorException() {
23 static final class PrivateCtorException extends Exception {
24 private static final long serialVersionUID = 1L;
26 private PrivateCtorException(final String message, final Throwable cause) {
27 super(message, cause);
31 static final class FailingCtorException extends Exception {
32 private static final long serialVersionUID = 1L;
34 FailingCtorException(final String message, final Throwable cause) {
35 throw new IllegalArgumentException("just for test");
39 public static final class GoodException extends Exception {
40 private static final long serialVersionUID = 1L;
42 public GoodException(final String message, final Throwable cause) {
43 super(message, cause);
48 @Test(expected = IllegalArgumentException.class)
49 public void testNoArgumentsContructor() {
50 ReflectiveExceptionMapper.create("no arguments", NoArgumentCtorException.class);
53 @Test(expected = IllegalArgumentException.class)
54 public void testPrivateContructor() {
55 ReflectiveExceptionMapper.create("private constructor", PrivateCtorException.class);
58 @Test(expected = IllegalArgumentException.class)
59 public void testFailingContructor() {
60 ReflectiveExceptionMapper.create("failing constructor", FailingCtorException.class);
64 public void testInstantiation() {
65 ReflectiveExceptionMapper<GoodException> mapper = ReflectiveExceptionMapper.create("instantiation",
68 final Throwable cause = new Throwable("some test message");
70 GoodException ret = mapper.apply(new ExecutionException("test", cause));
72 assertEquals("instantiation execution failed", ret.getMessage());
73 assertEquals(cause, ret.getCause());