Issue #23507 glassfish(bootstrap) uses junit5 instead of junit4 - and also doesn't swallow exceptions any more
diff --git a/nucleus/core/bootstrap/pom.xml b/nucleus/core/bootstrap/pom.xml index 7bb52d8..248aeb4 100755 --- a/nucleus/core/bootstrap/pom.xml +++ b/nucleus/core/bootstrap/pom.xml
@@ -69,8 +69,8 @@ <scope>provided</scope> </dependency> - <!-- Although we package simple-glassfish-api bundle's content in glassfish.jar, in standalone mode, we have to create - a launcher classloader that has the launching APIs and OSGi APIs in same level. SO, we need this jar to be part of distribution. + <!-- Although we package simple-glassfish-api bundle's content in glassfish.jar, in standalone mode, we have to create + a launcher classloader that has the launching APIs and OSGi APIs in same level. SO, we need this jar to be part of distribution. Making it a compile scoped dependency forces this jar to be part of all distribution. --> <dependency> <groupId>org.glassfish.main.common</groupId> @@ -95,6 +95,10 @@ </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + </dependency> + <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest</artifactId> </dependency> @@ -116,7 +120,7 @@ </configuration> </plugin> - <!-- We package simple-glassfish-api classes in this bundle for embedded scenario, we expect user to just bootstrap + <!-- We package simple-glassfish-api classes in this bundle for embedded scenario, we expect user to just bootstrap the runtime by installing glassfish.jar alone. --> <plugin> <artifactId>maven-dependency-plugin</artifactId>
diff --git a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/MainHelperTest.java b/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/MainHelperTest.java index 87f0fc1..3c4fb2c 100644 --- a/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/MainHelperTest.java +++ b/nucleus/core/bootstrap/src/test/java/com/sun/enterprise/glassfish/bootstrap/MainHelperTest.java
@@ -1,5 +1,6 @@ /* * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021 Contributors to the Eclipse Foundation * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,70 +17,67 @@ package com.sun.enterprise.glassfish.bootstrap; +import java.io.File; +import java.io.PrintWriter; +import java.util.Properties; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Created by kokil on 5/18/17. */ - -import static org.junit.Assert.*; -import org.junit.Test; -import java.io.*; -import java.util.*; - public class MainHelperTest { - /* This test is used to test the regex pattern of "parseAsEnv" method of "MainHelper.java". - It creates two temporary files (asenv.conf and asenv.bat) for testing purpose. - The "parseAsEnv()" method of "MainHelper.java" reads the "asenv.*" file line by line to generate - the Properties "asenvProps" whose assertion has been done in this unit test. - */ - + /** + * This test is used to test the regex pattern of "parseAsEnv" method of "MainHelper.java". + * <br> + * It creates two temporary files (asenv.conf and asenv.bat) for testing purpose. + * The "parseAsEnv()" method of "MainHelper.java" reads the "asenv.*" file line by line to + * generate the Properties "asenvProps" whose assertion has been done in this unit test. + */ @Test - public void parseAsEnvTest() { - try { - File resources = File.createTempFile("helperTestResources", "config"); - resources.delete(); // delete the temp file - resources.mkdir(); // reuse the name for a directory - resources.deleteOnExit(); - File config = new File(resources, "config"); - config.mkdir(); - config.deleteOnExit(); - File asenv_bat = new File(config, "asenv.bat"); //test resource for windows - File asenv_conf = new File(config, "asenv.conf");//test resource for linux - asenv_bat.deleteOnExit(); - asenv_conf.deleteOnExit(); + public void parseAsEnvTest() throws Exception { + File resources = File.createTempFile("helperTestResources", "config"); + resources.delete(); // delete the temp file + resources.mkdir(); // reuse the name for a directory + resources.deleteOnExit(); + File config = new File(resources, "config"); + config.mkdir(); + config.deleteOnExit(); + File asenv_bat = new File(config, "asenv.bat"); // test resource for windows + File asenv_conf = new File(config, "asenv.conf");// test resource for linux + asenv_bat.deleteOnExit(); + asenv_conf.deleteOnExit(); - PrintWriter pw1 = new PrintWriter(asenv_bat); - pw1.println("set AbcVar=value1"); - pw1.println("SET Avar=\"value2\""); - pw1.println("Set Bvar=\"value3\""); - pw1.println("set setVar=\"value4\""); - pw1.println("set SetVar=value5"); - pw1.println("set seVar=\"value6\""); - pw1.println("set sVar=\"value7\""); - pw1.close(); - PrintWriter pw2 = new PrintWriter(asenv_conf); - pw2.println("AbcVar=value1"); - pw2.println("Avar=\"value2\""); - pw2.println("Bvar=\"value3\""); - pw2.println("setVar=\"value4\""); - pw2.println("SetVar=value5"); - pw2.println("seVar=\"value6\""); - pw2.println("sVar=\"value7\""); - pw2.close(); + PrintWriter pw1 = new PrintWriter(asenv_bat); + pw1.println("set AbcVar=value1"); + pw1.println("SET Avar=\"value2\""); + pw1.println("Set Bvar=\"value3\""); + pw1.println("set setVar=\"value4\""); + pw1.println("set SetVar=value5"); + pw1.println("set seVar=\"value6\""); + pw1.println("set sVar=\"value7\""); + pw1.close(); + PrintWriter pw2 = new PrintWriter(asenv_conf); + pw2.println("AbcVar=value1"); + pw2.println("Avar=\"value2\""); + pw2.println("Bvar=\"value3\""); + pw2.println("setVar=\"value4\""); + pw2.println("SetVar=value5"); + pw2.println("seVar=\"value6\""); + pw2.println("sVar=\"value7\""); + pw2.close(); - File installRoot = new File(resources.toString()); - Properties asenvProps = MainHelper.parseAsEnv(installRoot); - assertEquals("value1",asenvProps.getProperty("AbcVar")); - assertEquals("value2",asenvProps.getProperty("Avar")); - assertEquals("value3",asenvProps.getProperty("Bvar")); - assertEquals("value4",asenvProps.getProperty("setVar")); - assertEquals("value5",asenvProps.getProperty("SetVar")); - assertEquals("value6",asenvProps.getProperty("seVar")); - assertEquals("value7",asenvProps.getProperty("sVar")); - } - catch (Exception e) { - e.printStackTrace(); - } + File installRoot = new File(resources.toString()); + Properties asenvProps = MainHelper.parseAsEnv(installRoot); + assertEquals("value1", asenvProps.getProperty("AbcVar")); + assertEquals("value2", asenvProps.getProperty("Avar")); + assertEquals("value3", asenvProps.getProperty("Bvar")); + assertEquals("value4", asenvProps.getProperty("setVar")); + assertEquals("value5", asenvProps.getProperty("SetVar")); + assertEquals("value6", asenvProps.getProperty("seVar")); + assertEquals("value7", asenvProps.getProperty("sVar")); } - }