diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2024-06-11 15:49:30 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2024-06-17 16:12:00 +0100 |
commit | dd15704b23b3b1e9508a5f615f066ffca46a7101 (patch) | |
tree | c3a1158fc288223fcb4173765e71637d844a3501 /tools/tools-common/src | |
parent | e9b746340711ddfccee7ac0f669ace626b1b3d46 (diff) |
Convert junit4 to junit5
- tools module
Issue-ID: POLICY-5041
Change-Id: I4fddc20e306e82db8af858ff2444f7e40c9e5acd
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'tools/tools-common/src')
5 files changed, 64 insertions, 60 deletions
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java index 80980bb34..62dd1c2db 100644 --- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java +++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,10 @@ package org.onap.policy.apex.tools.common; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import org.apache.commons.cli.Option; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -36,13 +36,15 @@ import org.slf4j.ext.XLoggerFactory; * * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ -public class CliParserTest { +class CliParserTest { private static final XLogger LOGGER = XLoggerFactory.getXLogger(CliParserTest.class); - /** Testapp version. */ + /** + * Test app version. + */ @Test - public void testappVersion() { + void testAppVersion() { final CliParser cli = new CliParser(); assertNotNull(cli); LOGGER.info(cli.getAppVersion()); @@ -52,7 +54,7 @@ public class CliParserTest { * testAddAndGetOptionException. */ @Test - public void testAddAndGetOptionException() { + void testAddAndGetOptionException() { final CliParser cli = new CliParser(); assertThatThrownBy(() -> { cli.addOption(null); @@ -63,7 +65,7 @@ public class CliParserTest { * testParseAndGetCli. */ @Test - public void testParseAndGetCli() { + void testParseAndGetCli() { final CliParser cli = new CliParser(); final Option option = new Option("g", "Good option."); cli.addOption(option); diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java index aefa92b9c..70c8d1e4d 100644 --- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java +++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,31 +24,30 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayOutputStream; import java.io.PrintStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for {@link Console}. - * */ -public class ConsoleTest { +class ConsoleTest { private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); private final PrintStream originalErr = System.err; - @Before + @BeforeEach public void setUpStreams() { System.setErr(new PrintStream(errContent)); } - @After + @AfterEach public void restoreStreams() { System.setErr(originalErr); } @Test - public void testConsole() { + void testConsole() { Console.CONSOLE.setAppName(null); Console.CONSOLE.info(""); Console.CONSOLE.error(""); @@ -61,23 +60,23 @@ public class ConsoleTest { Console.CONSOLE.setAppName(""); Console.CONSOLE.set(Console.TYPE_DEBUG, Console.TYPE_ERROR, Console.TYPE_INFO, Console.TYPE_PROGRESS, - Console.TYPE_WARNING, Console.TYPE_TRACE, Console.TYPE_STACKTRACE); + Console.TYPE_WARNING, Console.TYPE_TRACE, Console.TYPE_STACKTRACE); Console.CONSOLE.configure(Console.CONFIG_COLLECT_WARNINGS); logMessage(); assertThat(errContent.toString().trim()).contains("debug: debug message.") - .contains("error: error message.").contains("info message.").contains("progress: progress message.") - .contains("warning: warn message.").contains("trace: trace message.") - .contains("exception message: Exception message."); + .contains("error: error message.").contains("info message.").contains("progress: progress message.") + .contains("warning: warn message.").contains("trace: trace message.") + .contains("exception message: Exception message."); reset(); Console.CONSOLE.setAppName("ConsoleTest"); Console.CONSOLE.configure(Console.CONFIG_COLLECT_ERRORS); logMessage(); assertThat(errContent.toString().trim()) - .contains("ConsoleTest: debug: debug message.").contains("ConsoleTest: error: error message.") - .contains("ConsoleTest: info message.").contains("ConsoleTest: progress: progress message.") - .contains("ConsoleTest: warning: warn message.").contains("ConsoleTest: trace: trace message.") - .contains("ConsoleTest: exception message: Exception message."); + .contains("ConsoleTest: debug: debug message.").contains("ConsoleTest: error: error message.") + .contains("ConsoleTest: info message.").contains("ConsoleTest: progress: progress message.") + .contains("ConsoleTest: warning: warn message.").contains("ConsoleTest: trace: trace message.") + .contains("ConsoleTest: exception message: Exception message."); reset(); Console.CONSOLE.deActivate(Console.TYPE_DEBUG); @@ -94,7 +93,7 @@ public class ConsoleTest { Console.CONSOLE.setAppName(null); Console.CONSOLE.stacktrace(new Exception("Exception message.", new Throwable("test stacktrace!"))); assertThat(errContent.toString()).contains("exception message: Exception message.") - .contains("exception cause: java.lang.Throwable: test stacktrace!"); + .contains("exception cause: java.lang.Throwable: test stacktrace!"); reset(); } diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java index abc01b5e3..decbb4395 100644 --- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java +++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (c) 2020 Nordix Foundation. + * Copyright (c) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,32 +20,33 @@ package org.onap.policy.apex.tools.common; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.nio.file.FileSystems; import java.nio.file.Path; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class OutputFileTest { +class OutputFileTest { final String testFileName = "testing.txt"; final Path fp = FileSystems.getDefault().getPath(testFileName); File file = fp.toFile(); - @Before - public void beforeSetUp() { + @BeforeEach + void beforeSetUp() { if (file.exists()) { - file.delete(); + assertTrue(file.delete()); } } @Test - public void testToWriter() { + void testToWriter() { OutputFile testFile = new OutputFile(testFileName, false); testFile.validate(); file.setReadable(false); @@ -56,7 +57,7 @@ public class OutputFileTest { } @Test - public void testValidate() { + void testValidate() { OutputFile testFile = new OutputFile(testFileName, true); assertNull(testFile.validate()); file.setReadable(false); @@ -68,7 +69,7 @@ public class OutputFileTest { } @Test - public void testToOutputStream() { + void testToOutputStream() { OutputFile testFile = new OutputFile(testFileName, true); assertNotNull(testFile.toOutputStream()); file.setReadable(false); @@ -76,10 +77,10 @@ public class OutputFileTest { assertNull(testFile.toOutputStream()); } - @After - public void testDown() { + @AfterEach + void testDown() { if (file.exists()) { - file.delete(); + assertTrue(file.delete()); } } } diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java index 1dc8d53ef..f817dc152 100644 --- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java +++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ package org.onap.policy.apex.tools.common.docs; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; //// //// NOTE: This file contains tags for ASCIIDOC @@ -30,7 +30,7 @@ import static org.junit.Assert.assertNotNull; ////// end::** //// import org.apache.commons.cli.CommandLine; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.tools.common.CliOptions; import org.onap.policy.apex.tools.common.CliParser; import org.slf4j.ext.XLogger; @@ -41,14 +41,16 @@ import org.slf4j.ext.XLoggerFactory; * * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ -public class ExampleAppVersionTest { +class ExampleAppVersionTest { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ExampleAppVersionTest.class); - /** Test example app version. */ + /** + * Test example app version. + */ @Test - public void testExampleAppVersion() { - final String[] args = new String[] { "-v" }; + void testExampleAppVersion() { + final String[] args = new String[] {"-v"}; // tag::setupParser[] final CliParser cli = new CliParser(); @@ -60,7 +62,7 @@ public class ExampleAppVersionTest { // tag::processCliVersion[] // version is an exit option, print version and exit if (cmd.hasOption('v') || cmd.hasOption("version")) { - LOGGER.info("myApp" + " " + cli.getAppVersion()); + LOGGER.info("myApp {}", cli.getAppVersion()); return; } // end::processCliVersion[] diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java index c653cd0b2..0be41d685 100644 --- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java +++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ package org.onap.policy.apex.tools.common.docs; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; //// ////NOTE: This file contains tags for ASCIIDOC @@ -33,7 +33,7 @@ import static org.junit.Assert.assertNotNull; //// import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; -import org.junit.Test; +import org.junit.jupiter.api.Test; //tag::import[] import org.onap.policy.apex.tools.common.CliOptions; import org.onap.policy.apex.tools.common.CliParser; @@ -46,7 +46,7 @@ import org.slf4j.ext.XLoggerFactory; * * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ -public class ExampleCliParserTest { +class ExampleCliParserTest { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ExampleCliParserTest.class); @@ -54,8 +54,8 @@ public class ExampleCliParserTest { * Test example parser. */ @Test - public void testExampleParser() { - final String[] args = new String[] { "-h" }; + void testExampleParser() { + final String[] args = new String[] {"-h"}; // tag::setApp[] final String appName = "test-app"; @@ -79,7 +79,7 @@ public class ExampleCliParserTest { // help is an exit option, print usage and exit if (cmd.hasOption('h') || cmd.hasOption("help")) { final HelpFormatter formatter = new HelpFormatter(); - LOGGER.info(appName + " v" + cli.getAppVersion() + " - " + appDescription); + LOGGER.info(appName + " v{} - " + appDescription, cli.getAppVersion()); formatter.printHelp(appName, cli.getOptions()); return; } @@ -88,7 +88,7 @@ public class ExampleCliParserTest { // tag::processCliVersion[] // version is an exit option, print version and exit if (cmd.hasOption('v') || cmd.hasOption("version")) { - LOGGER.info(appName + " " + cli.getAppVersion()); + LOGGER.info(appName + " {}", cli.getAppVersion()); return; } // end::processCliVersion[] @@ -106,7 +106,7 @@ public class ExampleCliParserTest { // tag::someStartPrint[] LOGGER.info(appName + ": starting"); - LOGGER.info(" --> model file: " + modelFile); + LOGGER.info(" --> model file: {}", modelFile); // end::someStartPrint[] // tag::yourApp[] |