/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.security;

import io.spine.testing.UtilityClassTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("InvocationGuard should")
class InvocationGuardTest extends UtilityClassTest<InvocationGuard> {

    InvocationGuardTest() {
        super(InvocationGuard.class);
    }

    @Test
    @DisplayName("throw SecurityException if no classes are allowed")
    void nobodyAllowed() {
        assertThrowsOn(InvocationGuard::allowOnly);
    }

    @Test
    @DisplayName("throw SecurityException for not allowed class")
    void notAllowed() {
        assertThrowsOn(() -> InvocationGuard.allowOnly(
                "java.lang.String", "org.junit.jupiter.api.Test")
        );
    }

    @Test
    @DisplayName("does not throw on allowed class")
    void pass() {
        String callingClass = CallerProvider.instance()
                                            .getCallerClass()
                                            .getName();
        assertDoesNotThrow(
                () ->  InvocationGuard.allowOnly(callingClass)
        );
    }

    private static void assertThrowsOn(Executable executable) {
        assertThrows(SecurityException.class, executable);
    }
}

@@ -1264,28 +1264,22 @@
 s.assert
-DoesNot
 Throw
+s
 ;%0Aimport
@@ -1319,28 +1319,20 @@
 ertions.
-assertThrows
+fail
 ;%0A%0A@Disp
@@ -2181,34 +2181,14 @@
     
-assertDoesNotThrow(%0A      
+try %7B%0A
     
@@ -2193,21 +2193,16 @@
         
-() -%3E
   Invoca
@@ -2234,16 +2234,17 @@
 ngClass)
+;
 %0A       
@@ -2236,34 +2236,86 @@
 Class);%0A        
-);
+%7D catch (Exception e) %7B%0A            fail(e);%0A        %7D
 %0A    %7D%0A%0A    priv

Fix call security test