From 260c6d6d9f4e768c3e475afa93c227ab7696753a Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Thu, 16 Apr 2026 15:30:56 +0100 Subject: [PATCH 1/3] 8382264: Refactor java.logging TestNG tests to use JUnit --- .../util/logging/LogRecordThreadIdTest.java | 40 +++++++++---------- .../util/logging/LoggerSupplierAPIsTest.java | 24 +++++------ .../modules/GetResourceBundleTest.java | 25 +++++++----- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/test/jdk/java/util/logging/LogRecordThreadIdTest.java b/test/jdk/java/util/logging/LogRecordThreadIdTest.java index bf5fdf33e525f..fadd9c17b3223 100644 --- a/test/jdk/java/util/logging/LogRecordThreadIdTest.java +++ b/test/jdk/java/util/logging/LogRecordThreadIdTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,25 +28,23 @@ * @bug 8245302 * @summary test the relationship between * thread id long and int methods - * @build LogRecordThreadIdTest - * @run testng/othervm LogRecordThreadIdTest + * @run junit/othervm ${test.main.class} */ import java.util.logging.Level; import java.util.logging.LogRecord; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; - +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class LogRecordThreadIdTest { - LogRecord record, record1, record2; + private static LogRecord record, record1, record2; - @BeforeTest - public void setUp() throws Exception { + @BeforeAll + public static void setUp() throws Exception { record = new LogRecord(Level.INFO, "record"); record1 = new LogRecord(Level.INFO, "record1"); record2 = new LogRecord(Level.INFO, "record2"); @@ -60,10 +58,10 @@ record = new LogRecord(Level.INFO, "record"); public void testSetThreadId() { record.setThreadID(Integer.MAX_VALUE - 20); record1.setThreadID(Integer.MAX_VALUE - 1); - assertEquals(record.getLongThreadID(), Integer.MAX_VALUE - 20L); - assertEquals(record.getThreadID(), Integer.MAX_VALUE - 20); - assertEquals(record1.getThreadID(), Integer.MAX_VALUE - 1); - assertEquals(record1.getLongThreadID(), Integer.MAX_VALUE - 1); + assertEquals(Integer.MAX_VALUE - 20L, record.getLongThreadID()); + assertEquals(Integer.MAX_VALUE - 20, record.getThreadID()); + assertEquals(Integer.MAX_VALUE - 1, record1.getThreadID()); + assertEquals(Integer.MAX_VALUE - 1, record1.getLongThreadID()); } /** @@ -75,12 +73,12 @@ public void testSetLongThreadId() { record.setLongThreadID(Integer.MAX_VALUE - 20L); record1.setLongThreadID(Integer.MAX_VALUE + 10L); record2.setLongThreadID(Integer.MAX_VALUE); - assertEquals(record.getThreadID(), Integer.MAX_VALUE - 20); - assertEquals(record.getLongThreadID(), Integer.MAX_VALUE - 20L); - assertNotEquals(record1.getThreadID(), Integer.MAX_VALUE + 10L); - assertEquals(record1.getLongThreadID(), Integer.MAX_VALUE + 10L); - assertEquals(record2.getThreadID(), Integer.MAX_VALUE); - assertEquals(record2.getLongThreadID(), Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE - 20, record.getThreadID()); + assertEquals(Integer.MAX_VALUE - 20L, record.getLongThreadID()); + assertNotEquals(Integer.MAX_VALUE + 10L, record1.getThreadID()); + assertEquals(Integer.MAX_VALUE + 10L, record1.getLongThreadID()); + assertEquals(Integer.MAX_VALUE, record2.getThreadID()); + assertEquals(Integer.MAX_VALUE, record2.getLongThreadID()); } } diff --git a/test/jdk/java/util/logging/LoggerSupplierAPIsTest.java b/test/jdk/java/util/logging/LoggerSupplierAPIsTest.java index 1a32764482fd9..a1e62a2932a9a 100644 --- a/test/jdk/java/util/logging/LoggerSupplierAPIsTest.java +++ b/test/jdk/java/util/logging/LoggerSupplierAPIsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,7 @@ /* * @test * @bug 8005263 - * @run testng LoggerSupplierAPIsTest + * @run junit ${test.main.class} */ import java.util.logging.Logger; @@ -37,11 +37,10 @@ import java.util.List; import java.util.Collections; -import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; -@Test(groups="unit") public class LoggerSupplierAPIsTest { static class CountingSupplier implements Supplier { AtomicInteger sno = new AtomicInteger(); @@ -217,25 +216,26 @@ private void testLevelConvenientMethods() { } private void validate(int index, boolean thrown, String methodName) { - assertEquals(supplier.getCount(), invokes[index]); - assertEquals(handler.getCount(), log_count[index]); + assertEquals(invokes[index], supplier.getCount()); + assertEquals(log_count[index], handler.getCount()); // Verify associated Throwable is right if (thrown) { for (LogRecord r: handler.getLogs()) { - assertTrue(r.getThrown() instanceof HelperEx, "Validate Thrown"); + assertInstanceOf(HelperEx.class, r.getThrown(), "Validate Thrown"); HelperEx e = (HelperEx) r.getThrown(); - assertEquals(r.getLevel(), e.getLevel(), "Validate Thrown Log Level"); + assertEquals(e.getLevel(), r.getLevel(), "Validate Thrown Log Level"); } } if (methodName != null) { for (LogRecord r: handler.getLogs()) { - assertEquals(r.getSourceClassName(), getClass().getName()); - assertEquals(r.getSourceMethodName(), methodName); + assertEquals(getClass().getName(), r.getSourceClassName()); + assertEquals(methodName, r.getSourceMethodName()); } } } + @Test public void verifyLogLevel() { for (int i = 0; i < levels.length; i++) { logger.setLevel(levels[i]); diff --git a/test/jdk/java/util/logging/modules/GetResourceBundleTest.java b/test/jdk/java/util/logging/modules/GetResourceBundleTest.java index f1f52401fc79f..c9932fafad651 100644 --- a/test/jdk/java/util/logging/modules/GetResourceBundleTest.java +++ b/test/jdk/java/util/logging/modules/GetResourceBundleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,15 +25,18 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; -import static jdk.test.lib.process.ProcessTools.*; + import jdk.test.lib.compiler.CompilerUtils; -import static org.testng.Assert.*; +import static jdk.test.lib.process.ProcessTools.executeTestJava; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -/** +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/* * @test * @bug 8129126 8136802 8137316 8137317 8136804 8139350 * @library /test/lib @@ -41,7 +44,7 @@ * java.logging * @build GetResourceBundleTest jdk.test.lib.process.ProcessTools * jdk.test.lib.compiler.CompilerUtils - * @run testng GetResourceBundleTest + * @run junit GetResourceBundleTest * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module, * resources are in named and unnamed modules respectively. * Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module. @@ -63,8 +66,8 @@ public class GetResourceBundleTest { /** * Compiles all modules used by the test, copy resource files. */ - @BeforeClass - public void setup() throws Exception { + @BeforeAll + public static void setup() throws Exception { // compile all modules for (String mn : modules) { Path msrc = MOD_SRC_DIR.resolve(mn); @@ -93,6 +96,6 @@ public void run() throws Exception { .outputTo(System.out) .errorTo(System.err) .getExitValue(); - assertTrue(exitValue == 0); + assertEquals(0, exitValue); } } From 3777f41d7da4a96831b8494a07106df5f752ade6 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Fri, 17 Apr 2026 09:09:11 +0100 Subject: [PATCH 2/3] Review feedback --- test/jdk/java/util/logging/modules/GetResourceBundleTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/java/util/logging/modules/GetResourceBundleTest.java b/test/jdk/java/util/logging/modules/GetResourceBundleTest.java index c9932fafad651..734a3918bc5e0 100644 --- a/test/jdk/java/util/logging/modules/GetResourceBundleTest.java +++ b/test/jdk/java/util/logging/modules/GetResourceBundleTest.java @@ -44,7 +44,7 @@ * java.logging * @build GetResourceBundleTest jdk.test.lib.process.ProcessTools * jdk.test.lib.compiler.CompilerUtils - * @run junit GetResourceBundleTest + * @run junit ${test.main.class} * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module, * resources are in named and unnamed modules respectively. * Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module. From 19e52fdc2bd57a4d0a6ea5afb78e3527e3dfe4db Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Mon, 27 Apr 2026 15:34:19 +0100 Subject: [PATCH 3/3] Review feedback --- .../util/logging/LogRecordThreadIdTest.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/test/jdk/java/util/logging/LogRecordThreadIdTest.java b/test/jdk/java/util/logging/LogRecordThreadIdTest.java index fadd9c17b3223..fd060ba29784f 100644 --- a/test/jdk/java/util/logging/LogRecordThreadIdTest.java +++ b/test/jdk/java/util/logging/LogRecordThreadIdTest.java @@ -34,28 +34,21 @@ import java.util.logging.Level; import java.util.logging.LogRecord; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; public class LogRecordThreadIdTest { - private static LogRecord record, record1, record2; - - @BeforeAll - public static void setUp() throws Exception { - record = new LogRecord(Level.INFO, "record"); - record1 = new LogRecord(Level.INFO, "record1"); - record2 = new LogRecord(Level.INFO, "record2"); - } - /** * Tests threadID setter methods for consistency * with longThreadID */ @Test public void testSetThreadId() { + LogRecord record = new LogRecord(Level.INFO, "record"); + LogRecord record1 = new LogRecord(Level.INFO, "record1"); + record.setThreadID(Integer.MAX_VALUE - 20); record1.setThreadID(Integer.MAX_VALUE - 1); assertEquals(Integer.MAX_VALUE - 20L, record.getLongThreadID()); @@ -70,15 +63,18 @@ public void testSetThreadId() { */ @Test public void testSetLongThreadId() { - record.setLongThreadID(Integer.MAX_VALUE - 20L); - record1.setLongThreadID(Integer.MAX_VALUE + 10L); - record2.setLongThreadID(Integer.MAX_VALUE); - assertEquals(Integer.MAX_VALUE - 20, record.getThreadID()); - assertEquals(Integer.MAX_VALUE - 20L, record.getLongThreadID()); - assertNotEquals(Integer.MAX_VALUE + 10L, record1.getThreadID()); - assertEquals(Integer.MAX_VALUE + 10L, record1.getLongThreadID()); - assertEquals(Integer.MAX_VALUE, record2.getThreadID()); - assertEquals(Integer.MAX_VALUE, record2.getLongThreadID()); + LogRecord record = new LogRecord(Level.INFO, "record"); + LogRecord record1 = new LogRecord(Level.INFO, "record1"); + LogRecord record2 = new LogRecord(Level.INFO, "record2"); + record.setLongThreadID(Integer.MAX_VALUE - 20L); + record1.setLongThreadID(Integer.MAX_VALUE + 10L); + record2.setLongThreadID(Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE - 20, record.getThreadID()); + assertEquals(Integer.MAX_VALUE - 20L, record.getLongThreadID()); + assertNotEquals(Integer.MAX_VALUE + 10L, record1.getThreadID()); + assertEquals(Integer.MAX_VALUE + 10L, record1.getLongThreadID()); + assertEquals(Integer.MAX_VALUE, record2.getThreadID()); + assertEquals(Integer.MAX_VALUE, record2.getLongThreadID()); } }