Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 24 additions & 30 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,42 +28,33 @@
* @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.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class LogRecordThreadIdTest {

LogRecord record, record1, record2;

@BeforeTest
public 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(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 @@ -72,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(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);
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());
}
}
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 ${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.
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);
}
}