|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with 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, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.doris.common.util; |
| 19 | + |
| 20 | +import org.junit.jupiter.api.Assertions; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +public class UtilTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void getRootCauseWithSuppressedMessageRootCauseWithMessageNoSuppressed() { |
| 27 | + Exception rootCause = new Exception("Root cause message"); |
| 28 | + Assertions.assertEquals("java.lang.Exception: Root cause message", |
| 29 | + Util.getRootCauseWithSuppressedMessage(rootCause)); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithSuppressed() { |
| 34 | + Exception rootCause = new Exception("Root cause message"); |
| 35 | + rootCause.addSuppressed(new Exception("Suppressed message")); |
| 36 | + Assertions.assertEquals( |
| 37 | + "java.lang.Exception: Root cause message With suppressed[0]:Suppressed message", |
| 38 | + Util.getRootCauseWithSuppressedMessage(rootCause)); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void getRootCauseWithSuppressedMessageRootCauseWithMessageWithMultiSuppressed() { |
| 43 | + Exception rootCause = new Exception("Root cause message"); |
| 44 | + rootCause.addSuppressed(new Exception("Suppressed message")); |
| 45 | + rootCause.addSuppressed(new Exception("Suppressed message2")); |
| 46 | + Assertions.assertEquals( |
| 47 | + "java.lang.Exception: Root cause message" |
| 48 | + + " With suppressed[0]:Suppressed message" |
| 49 | + + " With suppressed[1]:Suppressed message2", |
| 50 | + Util.getRootCauseWithSuppressedMessage(rootCause)); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageNoSuppressed() { |
| 55 | + Exception rootCause = new Exception(); |
| 56 | + Assertions.assertEquals("java.lang.Exception", Util.getRootCauseWithSuppressedMessage(rootCause)); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void getRootCauseWithSuppressedMessageRootCauseWithoutMessageWithSuppressed() { |
| 61 | + Exception rootCause = new Exception(); |
| 62 | + rootCause.addSuppressed(new Exception("Suppressed message")); |
| 63 | + Assertions.assertEquals( |
| 64 | + "java.lang.Exception With suppressed[0]:Suppressed message", |
| 65 | + Util.getRootCauseWithSuppressedMessage(rootCause)); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void getRootCauseWithSuppressedMessageChainedExceptionWithChainedSuppressed() { |
| 70 | + Exception rootCause = new Exception("Root cause message"); |
| 71 | + Exception chainedException = new Exception("Chained exception", rootCause); |
| 72 | + chainedException.addSuppressed(new Exception("Suppressed message")); |
| 73 | + Assertions.assertEquals("java.lang.Exception: Root cause message", |
| 74 | + Util.getRootCauseWithSuppressedMessage(chainedException)); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void getRootCauseWithSuppressedMessageChainedExceptionWithCauseSuppressed() { |
| 79 | + Exception rootCause = new Exception("Root cause message"); |
| 80 | + Exception chainedException = new Exception("Chained exception", rootCause); |
| 81 | + rootCause.addSuppressed(new Exception("Suppressed message")); |
| 82 | + Assertions.assertEquals( |
| 83 | + "java.lang.Exception: Root cause message With suppressed[0]:Suppressed message", |
| 84 | + Util.getRootCauseWithSuppressedMessage(chainedException)); |
| 85 | + } |
| 86 | +} |
0 commit comments