@@ -0,0 +1,3625 @@
+/*%0A * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage org.wso2.carbon.apimgt.gateway.handlers.common;%0A%0Aimport org.apache.synapse.MessageContext;%0Aimport org.apache.synapse.core.axis2.Axis2MessageContext;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mockito;%0Aimport org.powermock.api.mockito.PowerMockito;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0Aimport org.wso2.carbon.apimgt.gateway.utils.TransportHeaderUtil;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.TreeMap;%0A%0A@RunWith(PowerMockRunner.class)%0A@PrepareForTest(%7B TransportHeaderUtil.class%7D)%0Apublic class TransportHeaderUtilTest %7B%0A    private List%3CString%3E standardResponseHeaders = new ArrayList%3C%3E();%0A    private List%3CString%3E preserveHeaders = new ArrayList%3C%3E();%0A    private Map%3CString, String%3E requestHeaders = new TreeMap();%0A    private MessageContext messageContext;%0A%0A    @Before%0A    public void init() %7B%0A        standardResponseHeaders.add(%22respHeader1%22);%0A        standardResponseHeaders.add(%22respHeader2%22);%0A        requestHeaders.put(%22key%22, %22val%22);%0A        requestHeaders.put(%22key%22, %22val%22);%0A        PowerMockito.mockStatic(TransportHeaderUtil.class);%0A        messageContext = Mockito.mock(Axis2MessageContext.class);%0A    %7D%0A%0A    @Test%0A    public void removeExcessTransportHeadersWhenExcessHeadersNull() %7B%0A        PowerMockito.when(TransportHeaderUtil.getExcessTransportHeaders(messageContext)).thenReturn(null);%0A        try %7B%0A            TransportHeaderUtil.removeExcessTransportHeadersFromList(messageContext, this.standardResponseHeaders);%0A        %7D catch (NullPointerException e) %7B%0A            Assert.fail(%22Unexpected NullPointerException is thrown when excessTransportHeaders map is null when %22%0A                                            + %22trying to remove ExcessTransportHeadersFromList%22);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void removeTransportHeadersFromListWhenTransportHeadersNull() %7B%0A        PowerMockito.when(TransportHeaderUtil.getTransportHeaders(messageContext)).thenReturn(null);%0A        try %7B%0A            TransportHeaderUtil.removeTransportHeadersFromList(messageContext, this.standardResponseHeaders);%0A        %7D catch (NullPointerException e) %7B%0A            Assert.fail(%22Unexpected NullPointerException is thrown when transportHeaders map is null when %22%0A                                            + %22trying to remove TransportHeadersFromList%22);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void removeRequestHeadersFromNullResponseHeadersMap() %7B%0A        try %7B%0A            TransportHeaderUtil.removeRequestHeadersFromResponseHeaders(requestHeaders, null, preserveHeaders);%0A        %7D catch (NullPointerException e) %7B%0A            Assert.fail(%22Unexpected NullPointerException is thrown when trying to remove request headers from null %22%0A                                            + %22map of response headers%22);%0A        %7D%0A    %7D%0A%7D%0A%0A

Test cases for headers null scenarios in TransportHeaderUtil