From ef29a1f7751304a5dd73b2b5adfc895443e68f30 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 28 Jun 2024 01:12:05 +0200 Subject: [PATCH] Add StackTraceParser unit test --- .../utility/StackTraceParserTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 base/src/test/java/de/staropensource/sosengine/base/srctests/utility/StackTraceParserTest.java diff --git a/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/StackTraceParserTest.java b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/StackTraceParserTest.java new file mode 100644 index 0000000..8bf064c --- /dev/null +++ b/base/src/test/java/de/staropensource/sosengine/base/srctests/utility/StackTraceParserTest.java @@ -0,0 +1,65 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.base.srctests.utility; + +import de.staropensource.sosengine.base.utility.StackTraceParser; +import de.staropensource.sosengine.unittests.UnitLogger; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests the class {@link StackTraceParser}. + */ +@DisplayName("StackTraceParser") +class StackTraceParserTest { + /** + * The {@link UnitLogger} for this instance. + */ + private static final UnitLogger logger = new UnitLogger(StackTraceParserTest.class); + + /** + * Tests the method {@code getHeader}. + */ + @ParameterizedTest + @DisplayName("getHeader") + @ValueSource(strings = { + "", + "This is an example message", + "Some description here..." + }) + void testGetHeader(@NotNull String message) { + logger.testCall("testGetHeader", message); + + String output; + if (message.isEmpty()) + output = new StackTraceParser(new NumberFormatException()).getHeader(); + else + output = new StackTraceParser(new NumberFormatException(message)).getHeader(); + + String expected = "Caused by: " + NumberFormatException.class.getName(); + if (!message.isEmpty()) + expected += ": " + message; + assertEquals(expected, output, "Output \"" + output + "\" does not match expected output \"" + expected + "\""); + } +}