View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.commons.pool2.impl;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertTrue;
21  
22  import java.io.PrintWriter;
23  import java.io.StringWriter;
24  import java.util.stream.Stream;
25  
26  import org.junit.jupiter.params.ParameterizedTest;
27  import org.junit.jupiter.params.provider.Arguments;
28  import org.junit.jupiter.params.provider.MethodSource;
29  
30  public class CallStackTest {
31  
32      public static Stream<Arguments> data() {
33          // @formatter:off
34          return Stream.of(
35                  Arguments.arguments(new ThrowableCallStack("Test", false)),
36                  Arguments.arguments(new ThrowableCallStack("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", true)),
37                  Arguments.arguments(new SecurityManagerCallStack("Test", false)),
38                  Arguments.arguments(new SecurityManagerCallStack("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", true))
39          );
40          // @formatter:on
41      }
42  
43      private final StringWriter writer = new StringWriter();
44  
45      @ParameterizedTest
46      @MethodSource("data")
47      public void testPrintClearedStackTraceIsNoOp(final CallStack stack) {
48          stack.fillInStackTrace();
49          stack.clear();
50          stack.printStackTrace(new PrintWriter(writer));
51          final String stackTrace = writer.toString();
52          assertEquals("", stackTrace);
53      }
54  
55      @ParameterizedTest
56      @MethodSource("data")
57      public void testPrintFilledStackTrace(final CallStack stack) {
58          stack.fillInStackTrace();
59          stack.printStackTrace(new PrintWriter(writer));
60          final String stackTrace = writer.toString();
61          assertTrue(stackTrace.contains(getClass().getName()));
62      }
63  }