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.easymock.EasyMock.createMock;
019import static org.easymock.EasyMock.replay;
020import static org.easymock.EasyMock.verify;
021import static org.junit.jupiter.api.Assertions.assertEquals;
022
023import java.io.PrintWriter;
024import java.io.StringWriter;
025import java.io.Writer;
026
027import org.junit.jupiter.api.Test;
028
029import jakarta.servlet.http.HttpServletResponse;
030
031/**
032 * Tests {@link ExternalWriterHttpServletResponse}.
033 *
034 * <p>Copied from Apache tiles-request-servlet 1.0.7 and adapted for
035 * Jakarta EE 9 </p>
036 */
037public class ExternalWriterHttpServletResponseTest {
038
039    /**
040     * Empty default constructor
041     */
042    public ExternalWriterHttpServletResponseTest() {
043    }
044
045    /**
046     * Test method for {@link ExternalWriterHttpServletResponse#getWriter()}.
047     */
048    @Test
049    public void testGetWriter() {
050        HttpServletResponse wrappedResponse = createMock(HttpServletResponse.class);
051        Writer writer = new StringWriter();
052        PrintWriter printWriter = new PrintWriter(writer);
053        replay(wrappedResponse);
054        ExternalWriterHttpServletResponse response = new ExternalWriterHttpServletResponse(
055                wrappedResponse, printWriter);
056        assertEquals(printWriter, response.getWriter());
057        verify(wrappedResponse);
058    }
059}