/*
 * 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.logging.log4j.util;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Tests the StringBuilders class.
 */
public class StringBuildersTest {
    @Test
    public void trimToMaxSize() throws Exception {
        final StringBuilder sb = new StringBuilder();
        final char[] value = new char[4 * 1024];
        sb.append(value);

        assertTrue("needs trimming", sb.length() > Constants.MAX_REUSABLE_MESSAGE_SIZE);
        StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE);
        assertTrue("trimmed OK", sb.length() <= Constants.MAX_REUSABLE_MESSAGE_SIZE);
    }
}
@@ -1420,10 +1420,510 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void trimToMaxSizeWithLargeCapacity() throws Exception %7B%0A        final StringBuilder sb = new StringBuilder();%0A        final char%5B%5D value = new char%5B4 * 1024%5D;%0A        sb.append(value);%0A        sb.setLength(0);%0A%0A        assertTrue(%22needs trimming%22, sb.capacity() %3E Constants.MAX_REUSABLE_MESSAGE_SIZE);%0A        StringBuilders.trimToMaxSize(sb, Constants.MAX_REUSABLE_MESSAGE_SIZE);%0A        assertTrue(%22trimmed OK%22, sb.capacity() %3C= Constants.MAX_REUSABLE_MESSAGE_SIZE);%0A    %7D%0A%0A
 %0A%7D

update test case