Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit ba35a76

Browse files
committed
feat: Migrate JUnit 4 tests to JUnit 5 and adjust access modifiers
Updated test classes and methods to use JUnit 5 annotations and access modifiers. - Removed deprecated JUnit 4 annotations. - Changed public test classes and methods to package-private where appropriate. - Reverted accidental changes to BaseSystemTest and LocalLoggingImpl methods to maintain public access where required for compilation due to inheritance and interface implementation.
1 parent 88df393 commit ba35a76

10 files changed

Lines changed: 25 additions & 25 deletions

File tree

google-cloud-logging/src/test/java/com/google/cloud/logging/ExclusionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void testOf() {
100100
assertFalse(exclusion.isDisabled());
101101
}
102102

103-
public void compareExclusion(Exclusion expected, Exclusion actual) {
103+
void compareExclusion(Exclusion expected, Exclusion actual) {
104104
assertEquals(expected, actual);
105105
assertEquals(expected.toString(), actual.toString());
106106
assertEquals(expected.getName(), actual.getName());

google-cloud-logging/src/test/java/com/google/cloud/logging/InstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void testInvalidInstrumentationRemoved() {
102102
Instrumentation.getLibraryVersion(Instrumentation.class)))));
103103
}
104104

105-
public static JsonPayload generateInstrumentationPayload(
105+
static JsonPayload generateInstrumentationPayload(
106106
String libraryName, String libraryVersion) {
107107
Map<String, Object> jsonData = new HashMap<>();
108108
Map<String, Object> instrumentationData = new HashMap<>();

google-cloud-logging/src/test/java/com/google/cloud/logging/InvalidContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.jupiter.params.provider.MethodSource;
2525

2626
class InvalidContextTest {
27-
public static List<String> data() {
27+
static List<String> data() {
2828
final String[] INVALID_W3C_TRACE_CONTEXTS = {
2929
"",
3030
"abc/efg",

google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static class CustomLevel extends Level {
236236
}
237237
}
238238

239-
public final OutputStreamPatcher outputStreamPatcher = new OutputStreamPatcher();
239+
final OutputStreamPatcher outputStreamPatcher = new OutputStreamPatcher();
240240

241241
@BeforeEach
242242
void setUp() {

google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITLoggingTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ITLoggingTest extends BaseSystemTest {
5353
new MonitoredResource[] {GLOBAL_RESOURCE, CLOUDSQL_RESOURCE};
5454

5555
@BeforeAll
56-
public static void insertLogs() {
56+
static void insertLogs() {
5757
// This ensures predictability of the test:
5858
// with batching enabled by default, it's possible that for two log entries,
5959
// batching
@@ -81,7 +81,7 @@ public static void insertLogs() {
8181
}
8282

8383
@AfterAll
84-
public static void cleanUpLogs() throws InterruptedException {
84+
static void cleanUpLogs() throws InterruptedException {
8585
assertTrue(cleanupLog(LOG_ID));
8686
}
8787

@@ -90,7 +90,7 @@ public static void cleanUpLogs() throws InterruptedException {
9090
@Timeout(
9191
value = 600_000,
9292
unit = TimeUnit.MILLISECONDS) // Note: it can take ~10 minutes for logs to propagate!
93-
public void testListEntries() throws InterruptedException {
93+
void testListEntries() throws InterruptedException {
9494
LoggingOptions loggingOptions = logging.getOptions();
9595
LogName logName = LogName.ofProjectLogName(loggingOptions.getProjectId(), LOG_ID);
9696

@@ -127,7 +127,7 @@ public void testListEntries() throws InterruptedException {
127127
@Timeout(
128128
value = 600_000,
129129
unit = TimeUnit.MILLISECONDS) // Note: it can take ~10 minutes for logs to propagate!
130-
public void testSortedOrder() throws InterruptedException {
130+
void testSortedOrder() throws InterruptedException {
131131
LoggingOptions loggingOptions = logging.getOptions();
132132
LogName logName = LogName.ofProjectLogName(loggingOptions.getProjectId(), LOG_ID);
133133

google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class ITSinkTest extends BaseSystemTest {
4141

4242
@BeforeAll
43-
public static void setUp() {
43+
static void setUp() {
4444
// Cleanup all stucked sinks if any
4545
Logging.ListOption[] options = {Logging.ListOption.pageSize(50)};
4646
Page<Sink> sinkPage = logging.listSinks(options);

google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITTailLogsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ITTailLogsTest extends BaseSystemTest {
3838
MonitoredResource.newBuilder("global").build();
3939

4040
@AfterAll
41-
public static void cleanUpLogs() throws InterruptedException {
41+
static void cleanUpLogs() throws InterruptedException {
4242
assertTrue(cleanupLog(LOG_ID));
4343
}
4444

@@ -47,7 +47,7 @@ public static void cleanUpLogs() throws InterruptedException {
4747
@Timeout(
4848
value = 120_000,
4949
unit = TimeUnit.MILLISECONDS) // Note: the test should not take longer than 2 min
50-
public void testTailLogEntries() throws InterruptedException {
50+
void testTailLogEntries() throws InterruptedException {
5151
LogEntry testLogEntry =
5252
LogEntry.newBuilder(Payload.StringPayload.of("stringPayload1"))
5353
.addLabel("key1", "value1")

google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITTracingLogsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ITTracingLogsTest extends BaseSystemTest {
8181
private static LogName logName;
8282

8383
@BeforeAll
84-
public static void prepareLogs() throws InterruptedException {
84+
static void prepareLogs() throws InterruptedException {
8585
LoggingOptions loggingOptions = logging.getOptions();
8686
logName = LogName.ofProjectLogName(loggingOptions.getProjectId(), LOG_ID);
8787
logging.setWriteSynchronicity(Synchronicity.SYNC);
@@ -124,7 +124,7 @@ void cleanUpLogs() throws InterruptedException {
124124

125125
@Test
126126
@Timeout(value = 600_000, unit = TimeUnit.MILLISECONDS)
127-
public void testDetectW3CTraceId() throws InterruptedException {
127+
void testDetectW3CTraceId() throws InterruptedException {
128128
// Loads w3c tracing context and writes a log entry
129129
Context.Builder builder = Context.newBuilder();
130130
builder.loadW3CTraceParentContext(W3C_TRACE_CONTEXT);
@@ -147,7 +147,7 @@ public void testDetectW3CTraceId() throws InterruptedException {
147147

148148
@Test
149149
@Timeout(value = 600_000, unit = TimeUnit.MILLISECONDS)
150-
public void testDetectXCTCTraceId() throws InterruptedException {
150+
void testDetectXCTCTraceId() throws InterruptedException {
151151
// Loads cloud trace context and writes a log entry
152152
Context.Builder builder = Context.newBuilder();
153153
builder.loadCloudTraceContext(X_CLOUD_TRACE_CONTEXT);
@@ -171,7 +171,7 @@ public void testDetectXCTCTraceId() throws InterruptedException {
171171

172172
@Test
173173
@Timeout(value = 600_000, unit = TimeUnit.MILLISECONDS)
174-
public void testDetectOtelTraceId() throws InterruptedException {
174+
void testDetectOtelTraceId() throws InterruptedException {
175175
// Writes a log entry in open telemetry context
176176
writeLogEntryWithOtelContext(otelEntry);
177177

@@ -191,7 +191,7 @@ public void testDetectOtelTraceId() throws InterruptedException {
191191

192192
@Test
193193
@Timeout(value = 600_000, unit = TimeUnit.MILLISECONDS)
194-
public void testW3CTraceIdWithOtelContext() throws InterruptedException {
194+
void testW3CTraceIdWithOtelContext() throws InterruptedException {
195195
// Writes a log entry with W3C context and Open Telemetry context
196196
Context.Builder builder = Context.newBuilder();
197197
builder.loadW3CTraceParentContext(W3C_TRACE_CONTEXT);
@@ -214,7 +214,7 @@ public void testW3CTraceIdWithOtelContext() throws InterruptedException {
214214

215215
@Test
216216
@Timeout(value = 600_000, unit = TimeUnit.MILLISECONDS)
217-
public void testXCTCTraceIdWithOtelContext() throws InterruptedException {
217+
void testXCTCTraceIdWithOtelContext() throws InterruptedException {
218218
// Writes a log entry with cloud trace context and Open Telemetry context
219219
Context.Builder builder = Context.newBuilder();
220220
builder.loadCloudTraceContext(X_CLOUD_TRACE_CONTEXT);

google-cloud-logging/src/test/java/com/google/cloud/logging/v2/testing/LocalLoggingHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
import java.io.IOException;
2424

2525
/** LocalLoggingHelper runs an in-memory Logging server for use in tests. */
26-
public class LocalLoggingHelper {
26+
class LocalLoggingHelper {
2727
private final String address;
2828
private final Server server;
2929
private final LocalLoggingImpl loggingImpl;
3030

3131
/** Constructs a new LocalLoggingHelper. The method start() must be called before it is used. */
32-
public LocalLoggingHelper(String address) {
32+
LocalLoggingHelper(String address) {
3333
this.address = address;
3434
this.loggingImpl = new LocalLoggingImpl();
3535
this.server =
3636
InProcessServerBuilder.forName(address).addService(loggingImpl.bindService()).build();
3737
}
3838

3939
/** Starts the in-memory service. */
40-
public void start() {
40+
void start() {
4141
try {
4242
server.start();
4343
} catch (IOException ex) {
@@ -46,22 +46,22 @@ public void start() {
4646
}
4747

4848
/** Resets the state of the in-memory service. */
49-
public void reset() {
49+
void reset() {
5050
loggingImpl.reset();
5151
}
5252

5353
/** Returns the internal in-memory service. */
54-
public LocalLoggingImpl getLoggingImpl() {
54+
LocalLoggingImpl getLoggingImpl() {
5555
return loggingImpl;
5656
}
5757

5858
/** Creates a channel for making requests to the in-memory service. */
59-
public ManagedChannel createChannel() {
59+
ManagedChannel createChannel() {
6060
return InProcessChannelBuilder.forName(address).usePlaintext().build();
6161
}
6262

6363
/** Shuts down the in-memory service. */
64-
public void shutdownNow() {
64+
void shutdownNow() {
6565
server.shutdownNow();
6666
}
6767
}

google-cloud-logging/src/test/java/com/google/cloud/logging/v2/testing/LocalLoggingImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.List;
3434
import java.util.Map;
3535

36-
public class LocalLoggingImpl extends LoggingServiceV2Grpc.LoggingServiceV2ImplBase {
36+
class LocalLoggingImpl extends LoggingServiceV2Grpc.LoggingServiceV2ImplBase {
3737

3838
private final Map<String, List<LogEntry>> logs = new HashMap<>();
3939

0 commit comments

Comments
 (0)