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 final class ReflectiveExceptionMapperTest {
16 static final class NoArgumentCtorException extends Exception {
17 private static final long serialVersionUID = 1L;
19 public NoArgumentCtorException() {
24 static final class PrivateCtorException extends Exception {
25 private static final long serialVersionUID = 1L;
27 private PrivateCtorException(final String message, final Throwable cause) {
28 super(message, cause);
32 static final class FailingCtorException extends Exception {
33 private static final long serialVersionUID = 1L;
35 public FailingCtorException(final String message, final Throwable cause) {
36 throw new IllegalArgumentException("just for test");
40 static final class GoodException extends Exception {
41 private static final long serialVersionUID = 1L;
43 public GoodException(final String message, final Throwable cause) {
44 super(message, cause);
49 @Test(expected=IllegalArgumentException.class)
50 public void testNoArgumentsContructor() {
51 ReflectiveExceptionMapper.create("no arguments", NoArgumentCtorException.class);
54 @Test(expected=IllegalArgumentException.class)
55 public void testPrivateContructor() {
56 ReflectiveExceptionMapper.create("private constructor", PrivateCtorException.class);
59 @Test(expected=IllegalArgumentException.class)
60 public void testFailingContructor() {
61 ReflectiveExceptionMapper.create("failing constructor", FailingCtorException.class);
65 public void testInstantiation() {
66 ReflectiveExceptionMapper<GoodException> mapper = ReflectiveExceptionMapper.create("instantiation", GoodException.class);
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());