// Path: src/main/java/com/google/code/tempusfugit/ExceptionWrapper.java
// public class ExceptionWrapper {
// 
//     public static <V> V wrapAsRuntimeException(Callable<V> callable) throws RuntimeException {
//         try {
//             return callable.call();
//         } catch (Exception e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static <V, E extends Exception> V wrapAnyException(Callable<V> callable, final WithException<E> wrapper) throws E {
//         try {
//             return callable.call();
//         } catch (Throwable e) {
//             throw newException(wrapper, e).create();
//         }
//     }
// 
//     public static void throwAsRuntimeException(Exception throwable) {
//         throw new RuntimeException(throwable);
//     }
// 
//     public static <E extends RuntimeException> void throwException(Exception throwable, WithException<E> wrapper) throws E {
//         throw newException(wrapper, throwable).create();
//     }
// 
//     static class ExceptionFactory<E extends Exception> implements Factory<E> {
//         private final Class<E> wrapped;
//         private final Throwable throwable;
// 
//         static <E extends Exception> ExceptionFactory<E> newException(WithException<E> wrapped, Throwable throwable) {
//             return new ExceptionFactory<>(wrapped.getType(), throwable);
//         }
// 
//         private ExceptionFactory(Class<E> wrapped, Throwable throwable) {
//             this.wrapped = wrapped;
//             this.throwable = throwable;
//         }
// 
//         @Override
//         public E create() throws FactoryException {
//             try {
//                 Constructor<E> constructor = wrapped.getConstructor(Throwable.class);
//                 return constructor.newInstance(throwable);
//             } catch (Exception e) {
//                 throw new FactoryException(e);
//             }
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/google/code/tempusfugit/WithException.java
// public static <E extends Exception> WithException<E> as(Class<E> type) {
//     return new WithException<>(type);
// }
// 
// Path: src/main/java/com/google/code/tempusfugit/WithException.java
// public static <E extends Exception> WithException<E> with(Class<E> type) {
//     return new WithException<>(type);
// }


import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.api.Action;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import java.util.concurrent.Callable;
import static com.google.code.tempusfugit.ExceptionWrapper.*;
import static com.google.code.tempusfugit.WithException.as;
import static com.google.code.tempusfugit.WithException.with;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.core.Is.is;
import static org.jmock.Expectations.returnValue;
import static org.jmock.Expectations.throwException;
/*
 * Copyright (c) 2009-2018, toby weston & tempus-fugit committers
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 *      http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package com.google.code.tempusfugit;




@RunWith(JMock.class)
public class ExceptionWrapperTest {

    @Rule public ExpectedException exception = ExpectedException.none();

    private final Mockery context = new JUnit4Mockery();
    private final Callable<String> callable = context.mock(Callable.class);

    public void exampleLambdaSyntax() throws SomeOtherCheckedException {
        wrapAnyException(() -> null, with(SomeOtherCheckedException.class));
    }

    @Test
    public void shouldDelegateCallReflectiveException() throws Exception {
        callWill(returnValue("value"));
// Path: src/main/java/com/google/code/tempusfugit/ExceptionWrapper.java
// public class ExceptionWrapper {
// 
//     public static <V> V wrapAsRuntimeException(Callable<V> callable) throws RuntimeException {
//         try {
//             return callable.call();
//         } catch (Exception e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static <V, E extends Exception> V wrapAnyException(Callable<V> callable, final WithException<E> wrapper) throws E {
//         try {
//             return callable.call();
//         } catch (Throwable e) {
//             throw newException(wrapper, e).create();
//         }
//     }
// 
//     public static void throwAsRuntimeException(Exception throwable) {
//         throw new RuntimeException(throwable);
//     }
// 
//     public static <E extends RuntimeException> void throwException(Exception throwable, WithException<E> wrapper) throws E {
//         throw newException(wrapper, throwable).create();
//     }
// 
//     static class ExceptionFactory<E extends Exception> implements Factory<E> {
//         private final Class<E> wrapped;
//         private final Throwable throwable;
// 
//         static <E extends Exception> ExceptionFactory<E> newException(WithException<E> wrapped, Throwable throwable) {
//             return new ExceptionFactory<>(wrapped.getType(), throwable);
//         }
// 
//         private ExceptionFactory(Class<E> wrapped, Throwable throwable) {
//             this.wrapped = wrapped;
//             this.throwable = throwable;
//         }
// 
//         @Override
//         public E create() throws FactoryException {
//             try {
//                 Constructor<E> constructor = wrapped.getConstructor(Throwable.class);
//                 return constructor.newInstance(throwable);
//             } catch (Exception e) {
//                 throw new FactoryException(e);
//             }
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/google/code/tempusfugit/WithException.java
// public static <E extends Exception> WithException<E> as(Class<E> type) {
//     return new WithException<>(type);
// }
// 
// Path: src/main/java/com/google/code/tempusfugit/WithException.java
// public static <E extends Exception> WithException<E> with(Class<E> type) {
//     return new WithException<>(type);
// }


// Path: src/test/java/com/google/code/tempusfugit/ExceptionWrapperTest.java
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.api.Action;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import java.util.concurrent.Callable;
import static com.google.code.tempusfugit.ExceptionWrapper.*;
import static com.google.code.tempusfugit.WithException.as;
import static com.google.code.tempusfugit.WithException.with;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.sameInstance;
import static org.hamcrest.core.Is.is;
import static org.jmock.Expectations.returnValue;
import static org.jmock.Expectations.throwException;

/*
 * Copyright (c) 2009-2018, toby weston & tempus-fugit committers
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 *      http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package com.google.code.tempusfugit;




@RunWith(JMock.class)
public class ExceptionWrapperTest {

    @Rule public ExpectedException exception = ExpectedException.none();

    private final Mockery context = new JUnit4Mockery();
    private final Callable<String> callable = context.mock(Callable.class);

    public void exampleLambdaSyntax() throws SomeOtherCheckedException {
        wrapAnyException(() -> null, with(SomeOtherCheckedException.class));
    }

    @Test
    public void shouldDelegateCallReflectiveException() throws Exception {
        callWill(returnValue("value"));
        assertThat(wrapAnyException(callable, with(SomeOtherCheckedException.class)), is("value"));