001/*
002 * Copyright 2023 Web-Legacy
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.apache.tiles.request.jakarta.servlet;
017
018import static org.junit.jupiter.api.Assertions.assertEquals;
019import static org.junit.jupiter.api.Assertions.assertNull;
020
021import org.junit.jupiter.api.Test;
022
023/**
024 * Tests {@link NotAServletEnvironmentException}.
025 *
026 * <p>Copied from Apache tiles-request-servlet 1.0.7 and adapted for
027 * Jakarta EE 9.</p>
028 */
029public class NotAServletEnvironmentExceptionTest {
030
031    /**
032     * Empty default constructor
033     */
034    public NotAServletEnvironmentExceptionTest() {
035    }
036
037    /**
038     * Test method for {@link NotAServletEnvironmentException#NotAServletEnvironmentException()}.
039     */
040    @Test
041    public void testNotAServletEnvironmentException() {
042        NotAServletEnvironmentException exception = new NotAServletEnvironmentException();
043        assertNull(exception.getMessage());
044        assertNull(exception.getCause());
045    }
046
047    /**
048     * Test method for {@link NotAServletEnvironmentException#NotAServletEnvironmentException(String)}.
049     */
050    @Test
051    public void testNotAServletEnvironmentExceptionString() {
052        NotAServletEnvironmentException exception = new NotAServletEnvironmentException("my message");
053        assertEquals("my message", exception.getMessage());
054        assertNull(exception.getCause());
055    }
056
057    /**
058     * Test method for {@link NotAServletEnvironmentException#NotAServletEnvironmentException(Throwable)}.
059     */
060    @Test
061    public void testNotAServletEnvironmentExceptionThrowable() {
062        Throwable cause = new Throwable();
063        NotAServletEnvironmentException exception = new NotAServletEnvironmentException(cause);
064        assertEquals(cause.toString(), exception.getMessage());
065        assertEquals(cause, exception.getCause());
066    }
067
068    /**
069     * Test method for {@link NotAServletEnvironmentException#NotAServletEnvironmentException(String, Throwable)}.
070     */
071    @Test
072    public void testNotAServletEnvironmentExceptionStringThrowable() {
073        Throwable cause = new Throwable();
074        NotAServletEnvironmentException exception = new NotAServletEnvironmentException("my message", cause);
075        assertEquals("my message", exception.getMessage());
076        assertEquals(cause, exception.getCause());
077    }
078}