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;
14 import org.junit.Test;
16 public final class ReflectiveExceptionMapperTest {
17 static final class NoArgumentCtorException extends Exception {
18 private static final long serialVersionUID = 1L;
20 public NoArgumentCtorException() {
25 static final class PrivateCtorException extends Exception {
26 private static final long serialVersionUID = 1L;
28 private PrivateCtorException(final String message, final Throwable cause) {
29 super(message, cause);
33 static final class FailingCtorException extends Exception {
34 private static final long serialVersionUID = 1L;
36 public FailingCtorException(final String message, final Throwable cause) {
37 throw new IllegalArgumentException("just for test");
41 static final class GoodException extends Exception {
42 private static final long serialVersionUID = 1L;
44 public GoodException(final String message, final Throwable cause) {
45 super(message, cause);
50 @Test(expected=IllegalArgumentException.class)
51 public void testNoArgumentsContructor() {
52 ReflectiveExceptionMapper.create("no arguments", NoArgumentCtorException.class);
55 @Test(expected=IllegalArgumentException.class)
56 public void testPrivateContructor() {
57 ReflectiveExceptionMapper.create("private constructor", PrivateCtorException.class);
60 @Test(expected=IllegalArgumentException.class)
61 public void testFailingContructor() {
62 ReflectiveExceptionMapper.create("failing constructor", FailingCtorException.class);
66 public void testInstantiation() {
67 ReflectiveExceptionMapper<GoodException> mapper = ReflectiveExceptionMapper.create("instantiation", GoodException.class);
69 final Throwable cause = new Throwable("some test message");
71 GoodException ret = mapper.apply(new ExecutionException("test", cause));
73 assertEquals("instantiation execution failed", ret.getMessage());
74 assertEquals(cause, ret.getCause());