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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertThrows;
13 import java.util.concurrent.ExecutionException;
14 import org.junit.jupiter.api.Test;
16 public class ReflectiveExceptionMapperTest {
17 public static final class NoArgumentCtorException extends Exception {
19 private static final long serialVersionUID = 1L;
21 public NoArgumentCtorException() {
26 public static final class PrivateCtorException extends Exception {
28 private static final long serialVersionUID = 1L;
30 private PrivateCtorException(final String message, final Throwable cause) {
31 super(message, cause);
35 public static final class FailingCtorException extends Exception {
37 private static final long serialVersionUID = 1L;
39 public FailingCtorException(final String message, final Throwable cause) {
40 throw new IllegalArgumentException("just for test");
44 public static final class GoodException extends Exception {
46 private static final long serialVersionUID = 1L;
48 public GoodException(final String message, final Throwable cause) {
49 super(message, cause);
55 void testNoArgumentsContructor() {
56 assertThrows(IllegalArgumentException.class,
57 () -> ReflectiveExceptionMapper.create("no arguments", NoArgumentCtorException.class));
61 void testPrivateContructor() {
62 assertThrows(IllegalArgumentException.class,
63 () -> ReflectiveExceptionMapper.create("private constructor", PrivateCtorException.class));
67 void testFailingContructor() {
68 assertThrows(IllegalArgumentException.class,
69 () -> ReflectiveExceptionMapper.create("failing constructor", FailingCtorException.class));
73 void testInstantiation() {
74 final var mapper = ReflectiveExceptionMapper.create("instantiation", GoodException.class);
75 final var cause = new Throwable("some test message");
76 final var ret = mapper.apply(new ExecutionException("test", cause));
78 assertEquals("instantiation execution failed", ret.getMessage());
79 assertEquals(cause, ret.getCause());