/*
 * Copyright (C) Posten Norge AS
 *
 * 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 no.digipost.function;

import org.junit.jupiter.api.Test;

import java.util.function.Consumer;
import java.util.function.Supplier;

import static java.util.Optional.empty;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static uk.co.probablyfine.matchers.Java8Matchers.where;

public class ThrowingSupplierTest {

    private final RuntimeException ex = new RuntimeException();

    private final Error err = new Error();

    @Test
    public void rethrowOriginalRuntimeException() {
        ThrowingSupplier<?, Exception> fn = () -> {throw ex;};
        assertThat(assertThrows(RuntimeException.class, fn.asUnchecked()::get), sameInstance(ex));
    }

    @Test
    void allowsNull() {
        ThrowingSupplier<?, Exception> yieldsNull = () -> null;
        assertThat(yieldsNull.asUnchecked(), where(Supplier::get, nullValue()));
    }

    @Test
    public void rethrowOriginalError() {
        ThrowingSupplier<?, Exception> fn = () -> {throw err;};
        assertThat(assertThrows(Error.class, fn.asUnchecked()::get), sameInstance(err));
    }

    @Test
    public void translateToEmptyOptionalAndDelegateExceptionToHandler() {
        ThrowingSupplier<?, Exception> fn = () -> {throw ex;};
        @SuppressWarnings("unchecked")
        Consumer<Exception> handler = mock(Consumer.class);

        assertThat(fn.ifException(handler).get(), is(empty()));
        verify(handler, times(1)).accept(ex);
    }
}

@@ -1213,23 +1213,16 @@
 where;%0A%0A
-public 
 class Th
@@ -1242,16 +1242,16 @@
 rTest %7B%0A
+
 %0A    pri
@@ -1358,39 +1358,32 @@
 %0A%0A    @Test%0A    
-public 
 void rethrowOrig
@@ -1754,32 +1754,33 @@
 lue()));%0A    %7D%0A%0A
+%0A
     @Test%0A    pu
@@ -1773,31 +1773,24 @@
   @Test%0A    
-public 
 void rethrow
@@ -1985,15 +1985,8 @@
     
-public 
 void
@@ -2317,16 +2317,17 @@
 pt(ex);%0A
-
     %7D%0A
+%0A
 %7D%0A

Remove public modifiers