mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 14:27:59 +01:00
Migrate service tests to JUnit 5
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
/*
|
||||
* Copyright 2013-2020 Signal Messenger, LLC
|
||||
* Copyright 2013-2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.metrics;
|
||||
|
||||
import junitparams.JUnitParamsRunner;
|
||||
import junitparams.Parameters;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Map;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@RunWith(JUnitParamsRunner.class)
|
||||
public class OperatingSystemMemoryGaugeTest {
|
||||
class OperatingSystemMemoryGaugeTest {
|
||||
|
||||
private static final String MEMINFO =
|
||||
"""
|
||||
@@ -74,13 +70,13 @@ public class OperatingSystemMemoryGaugeTest {
|
||||
DirectMap1G: 2097152 kB
|
||||
""";
|
||||
|
||||
@Test
|
||||
@Parameters(method = "argumentsForTestGetValue")
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentsForTestGetValue")
|
||||
public void testGetValue(final String metricName, final long expectedValue) {
|
||||
assertEquals(expectedValue, new OperatingSystemMemoryGauge(metricName).getValue(MEMINFO.lines()));
|
||||
}
|
||||
|
||||
private static Object argumentsForTestGetValue() {
|
||||
private static Object[] argumentsForTestGetValue() {
|
||||
return new Object[] {
|
||||
new Object[] { "MemTotal", 16052208L },
|
||||
new Object[] { "Active(anon)", 5580980L },
|
||||
|
||||
@@ -5,23 +5,20 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.metrics;
|
||||
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import junitparams.JUnitParamsRunner;
|
||||
import junitparams.Parameters;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
class UserAgentTagUtilTest {
|
||||
|
||||
@RunWith(JUnitParamsRunner.class)
|
||||
public class UserAgentTagUtilTest {
|
||||
|
||||
@Test
|
||||
@Parameters(method = "argumentsForTestGetUserAgentTags")
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentsForTestGetUserAgentTags")
|
||||
public void testGetUserAgentTags(final String userAgent, final List<Tag> expectedTags) {
|
||||
assertEquals(new HashSet<>(expectedTags),
|
||||
new HashSet<>(UserAgentTagUtil.getUserAgentTags(userAgent)));
|
||||
@@ -32,7 +29,7 @@ public class UserAgentTagUtilTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Object argumentsForTestGetUserAgentTags() {
|
||||
private static Object[] argumentsForTestGetUserAgentTags() {
|
||||
return new Object[] {
|
||||
new Object[] { "This is obviously not a reasonable User-Agent string.", UserAgentTagUtil.UNRECOGNIZED_TAGS },
|
||||
new Object[] { null, UserAgentTagUtil.UNRECOGNIZED_TAGS },
|
||||
@@ -52,7 +49,7 @@ public class UserAgentTagUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserAgentTagsFlooded() {
|
||||
void testGetUserAgentTagsFlooded() {
|
||||
for (int i = 0; i < UserAgentTagUtil.MAX_VERSIONS; i++) {
|
||||
UserAgentTagUtil.getUserAgentTags(String.format("Signal-Android 4.0.%d (Android 8.1)", i));
|
||||
}
|
||||
@@ -67,13 +64,13 @@ public class UserAgentTagUtilTest {
|
||||
assertTrue(tags.contains(Tag.of(UserAgentTagUtil.VERSION_TAG, "4.0.0")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Parameters(method = "argumentsForTestGetPlatformTag")
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentsForTestGetPlatformTag")
|
||||
public void testGetPlatformTag(final String userAgent, final Tag expectedTag) {
|
||||
assertEquals(expectedTag, UserAgentTagUtil.getPlatformTag(userAgent));
|
||||
}
|
||||
|
||||
private Object argumentsForTestGetPlatformTag() {
|
||||
private static Object[] argumentsForTestGetPlatformTag() {
|
||||
return new Object[] {
|
||||
new Object[] { "This is obviously not a reasonable User-Agent string.", Tag.of(UserAgentTagUtil.PLATFORM_TAG, "unrecognized") },
|
||||
new Object[] { null, Tag.of(UserAgentTagUtil.PLATFORM_TAG, "unrecognized") },
|
||||
|
||||
Reference in New Issue
Block a user