Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions test/jdk/java/util/logging/LogRecordThreadIdTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LogRecordThreadIdTest previously used TestNG @BeforeTest, which runs before each @test method, so each test started with freshly constructed LogRecord instances. With JUnit @BeforeAll + static fields, the same instances are reused. The assertions still look safe because each test overwrites the state it cares about, but could you confirm this was intentional? If you want to preserve the old “fresh records per test” behavior, @beforeeach (possibly with non-static fields) would be closer to TestNG.

Copy link
Copy Markdown
Member Author

@dfuch dfuch Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand @BeforeTest means that the method will be run before any test in the test group. If there is no test group, the test group is the class. Which means that BeforeAll/BeforeTest/BeforeClass are all equivalent here. That said there's no real reason to use a setup method here. I simply removed it.

public static void setUp() throws Exception {
record = new LogRecord(Level.INFO, "record");
record1 = new LogRecord(Level.INFO, "record1");
record2 = new LogRecord(Level.INFO, "record2");
Expand All @@ -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());
}

/**
Expand All @@ -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());

}
}
24 changes: 12 additions & 12 deletions test/jdk/java/util/logging/LoggerSupplierAPIsTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +24,7 @@
/*
* @test
* @bug 8005263
* @run testng LoggerSupplierAPIsTest
* @run junit ${test.main.class}
*/

import java.util.logging.Logger;
Expand All @@ -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<String> {
AtomicInteger sno = new AtomicInteger();
Expand Down Expand Up @@ -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]);
Expand Down
25 changes: 14 additions & 11 deletions test/jdk/java/util/logging/modules/GetResourceBundleTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,23 +25,26 @@
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
* @modules jdk.compiler
* java.logging
* @build GetResourceBundleTest jdk.test.lib.process.ProcessTools
* jdk.test.lib.compiler.CompilerUtils
* @run testng GetResourceBundleTest
* @run junit GetResourceBundleTest
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this intentionally not use ${test.main.class}? (which you changed in the other test classes)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

* @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.
Expand All @@ -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);
Expand Down Expand Up @@ -93,6 +96,6 @@ public void run() throws Exception {
.outputTo(System.out)
.errorTo(System.err)
.getExitValue();
assertTrue(exitValue == 0);
assertEquals(0, exitValue);
}
}