/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.catalina.tribes.group.interceptors;

import java.util.Arrays;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class TestGzipInterceptor {

    @Test
    public void testSmallerThanBufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE / 2);
    }

    @Test
    public void testJustSmallerThanBufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE -1);
    }

    @Test
    public void testExactBufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE);
    }

    @Test
    public void testJustLargerThanBufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE + 1);
    }

    @Test
    public void testFactor2BufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 2);
    }

    @Test
    public void testFactor4BufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 4);
    }

    @Test
    public void testMuchLargerThanBufferSize() throws Exception {
        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 10 + 1000);
    }

    private void doCompressDecompress(int size) throws Exception {
        byte[] data = new byte[size];
        Arrays.fill(data, (byte)1);
        byte[] compress = GzipInterceptor.compress(data);
        byte[] result = GzipInterceptor.decompress(compress);
        assertTrue(Arrays.equals(data, result));
    }
}

@@ -878,372 +878,776 @@
 rray
-s;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport org.junit.Test;%0A%0Apublic class TestGzipInterceptor %7B%0A%0A    @Test%0A    public void testSmallerThanBufferSize() throws Exception %7B%0A        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE / 2);%0A    %7D%0A%0A    @Test%0A    public void testJustSmallerThanBufferSize() throws Exception %7B%0A        doCompressDecompress
+List;%0Aimport java.util.Arrays;%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0Aimport org.junit.runners.Parameterized.Parameter;%0Aimport org.junit.runners.Parameterized.Parameters;%0A%0A@RunWith(Parameterized.class)%0Apublic class TestGzipInterceptor %7B%0A%0A    @Parameters(name = %22%7Bindex%7D: bufferSize%5B%7B0%7D%5D%22)%0A    public static Collection%3CObject%5B%5D%3E inputs() %7B%0A        /// Note: These files are saved using the encoding indicated by the BOM%0A        List%3CObject%5B%5D%3E result = new ArrayList%3C%3E();%0A        result.add(new Object%5B%5D %7B Integer.valueOf(GzipInterceptor.DEFAULT_BUFFER_SIZE / 2) %7D);%0A        result.add(new Object%5B%5D %7B Integer.valueOf
 (Gzi
@@ -1684,114 +1684,65 @@
 ZE -
-1
+ 1) %7D
 );%0A    
-%7D%0A%0A
     
-@Test%0A    public void testExactBufferSize() throws Exception %7B%0A        doCompressDecompress
+result.add(new Object%5B%5D %7B Integer.valueOf
 (Gzi
@@ -1778,121 +1778,62 @@
 IZE)
+ %7D)
 ;%0A    
-%7D%0A%0A
     
-@Test%0A    public void testJustLargerThanBufferSize() throws Exception %7B%0A        doCompressDecompress
+result.add(new Object%5B%5D %7B Integer.valueOf
 (Gzi
@@ -1873,114 +1873,62 @@
 + 1)
+ %7D)
 ;%0A    
-%7D%0A%0A
     
-@Test%0A    public void testFactor2BufferSize() throws Exception %7B%0A        doCompressDecompress
+result.add(new Object%5B%5D %7B Integer.valueOf
 (Gzi
@@ -1968,114 +1968,62 @@
 * 2)
+ %7D)
 ;%0A    
-%7D%0A%0A
     
-@Test%0A    public void testFactor4BufferSize() throws Exception %7B%0A        doCompressDecompress
+result.add(new Object%5B%5D %7B Integer.valueOf
 (Gzi
@@ -2063,198 +2063,222 @@
 * 4)
+ %7D)
 ;%0A    
-%7D%0A%0A
     
-@Test%0A    public void testMuchLargerThanBufferSize() throws Exception %7B%0A        doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 10 + 1000);%0A    %7D%0A%0A    private
+result.add(new Object%5B%5D %7B Integer.valueOf(GzipInterceptor.DEFAULT_BUFFER_SIZE * 10 + 1000) %7D);%0A        return result;%0A    %7D%0A%0A    @Parameter(0)%0A    public int bufferSize;%0A%0A    @Test%0A    public
  void 
-do
+test
 Comp
@@ -2296,16 +2296,8 @@
 ess(
-int size
 ) th
@@ -2344,17 +2344,23 @@
 ew byte%5B
-s
+bufferS
 ize%5D;%0A  

Refactor to use parameterised tests (less code)