forked from StarOpenSource/Engine
Add StackTraceParser unit test
This commit is contained in:
parent
bba645f69b
commit
ef29a1f775
1 changed files with 65 additions and 0 deletions
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 + "\"");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue