Skip to content

Commit

Permalink
Remove remaining JUnit 4 usage (#4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim authored Apr 20, 2024
1 parent db623a8 commit a2a7db7
Show file tree
Hide file tree
Showing 50 changed files with 103 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.fasterxml.jackson.databind;

import com.google.common.testing.GcFinalization;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.openjdk.jol.info.GraphLayout;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class MapperFootprintTest {
/*
* Note: this class is run in an isolated execution in surefire. The test is too flaky with all the other tests
Expand All @@ -28,10 +29,10 @@ public void testMapperFootprint() throws InterruptedException {

// 29-Nov-2022, tatu: Should be under 10k, but... flakiness.
final int maxByteSize = 20_000;
Assert.assertTrue(
assertTrue(
mapperLayout.totalSize() < maxByteSize,
"ObjectMapper memory footprint ("+mapperLayout.totalSize()
+") exceeded limit ("+maxByteSize
+"). Footprint details: " + mapperLayout.toFootprint(),
mapperLayout.totalSize() < maxByteSize);
+"). Footprint details: " + mapperLayout.toFootprint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void testReading() throws Exception
assertEquals(1, citm.venueNames.size());
}

@Test
public void testRoundTrip() throws Exception
{
Citm citm = MAPPER.readValue(getClass().getResourceAsStream("/data/citm_catalog.json"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public void testAnySetterWithJsonNode() throws Exception
}

// [databind#4316]
@Test
public void testWithAnySetter() throws Exception
{
Problem4316 problem = new Problem4316();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.databind.deser;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JsonDeserializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Objects;

import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -12,6 +10,8 @@
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

import static com.fasterxml.jackson.annotation.JsonCreator.Mode.DELEGATING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class LocaleDeser4009Test
{
private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testLocaleWithFeatureDisabled() throws Exception
{
assertEquals(Locale.ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -122,11 +121,11 @@ public void testBooleanMapKeyDeserialization() throws Exception
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'true':'foobar'}}"), type);

assertEquals(1, result.map.size());
Assert.assertEquals(Boolean.TRUE, result.map.entrySet().iterator().next().getKey());
assertEquals(Boolean.TRUE, result.map.entrySet().iterator().next().getKey());

result = MAPPER.readValue(a2q("{'map':{'false':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Boolean.FALSE, result.map.entrySet().iterator().next().getKey());
assertEquals(Boolean.FALSE, result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -135,7 +134,7 @@ public void testByteMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Byte, String>> type = new TypeReference<MapWrapper<Byte, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'13':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Byte.valueOf((byte) 13), result.map.entrySet().iterator().next().getKey());
assertEquals(Byte.valueOf((byte) 13), result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -144,7 +143,7 @@ public void testShortMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Short, String>> type = new TypeReference<MapWrapper<Short, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'13':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Short.valueOf((short) 13), result.map.entrySet().iterator().next().getKey());
assertEquals(Short.valueOf((short) 13), result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -153,7 +152,7 @@ public void testIntegerMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Integer, String>> type = new TypeReference<MapWrapper<Integer, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'-3':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Integer.valueOf(-3), result.map.entrySet().iterator().next().getKey());
assertEquals(Integer.valueOf(-3), result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -162,7 +161,7 @@ public void testLongMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Long, String>> type = new TypeReference<MapWrapper<Long, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'42':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Long.valueOf(42), result.map.entrySet().iterator().next().getKey());
assertEquals(Long.valueOf(42), result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -171,7 +170,7 @@ public void testFloatMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Float, String>> type = new TypeReference<MapWrapper<Float, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'3.5':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Float.valueOf(3.5f), result.map.entrySet().iterator().next().getKey());
assertEquals(Float.valueOf(3.5f), result.map.entrySet().iterator().next().getKey());
}

@Test
Expand All @@ -180,7 +179,7 @@ public void testDoubleMapKeyDeserialization() throws Exception
TypeReference<MapWrapper<Double, String>> type = new TypeReference<MapWrapper<Double, String>>() { };
MapWrapper<?,?> result = MAPPER.readValue(a2q("{'map':{'0.25':'foobar'}}"), type);
assertEquals(1, result.map.size());
Assert.assertEquals(Double.valueOf(0.25), result.map.entrySet().iterator().next().getKey());
assertEquals(Double.valueOf(0.25), result.map.entrySet().iterator().next().getKey());
}

/*
Expand Down Expand Up @@ -215,7 +214,7 @@ public void testByteArrayMapKeyDeserialization() throws Exception
Map.Entry<byte[],String> entry = result.map.entrySet().iterator().next();
assertEquals("foobar", entry.getValue());
byte[] key = entry.getKey();
Assert.assertArrayEquals(binary, key);
assertArrayEquals(binary, key);
}

// [databind#2725]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private JsonNode _updateTreeWithArray(ObjectMapper mapper) throws Exception
return mapper.readerForUpdating(mergeTarget).readValue(updateNode);
}

@Test
public void testEnabledObjectNodeMerge() throws Exception {
final ObjectMapper mapperWithMerge = sharedMapper();

Expand All @@ -91,6 +92,7 @@ public void testEnabledObjectNodeMerge() throws Exception {
assertEquals(expected, merged);
}

@Test
public void testDisabledObjectNodeMerge() throws Exception {
ObjectMapper mapperNoObjectMerge = jsonMapperBuilder()
.withConfigOverride(ObjectNode.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void testDeserAsThrowable() throws Exception
_testDeserAsThrowable(MAPPER.writeValueAsString(new CustomThrowable4071()));
}

@Test
private void _testDeserAsThrowable(String exStr) throws Exception
{
assertNotNull(MAPPER.readValue(exStr, Throwable.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.junit.jupiter.api.Test;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests for serialization and deserialization of objects based on
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.fasterxml.jackson.databind.jsontype.deftyping;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -103,6 +102,6 @@ public void testWithCreatorAndJsonValue() throws Exception
assertNotNull(result.value);
assertEquals(Bean1385.class, result.value.getClass());
Bean1385 b = (Bean1385) result.value;
Assert.assertArrayEquals(BYTES, b.raw);
assertArrayEquals(BYTES, b.raw);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.fasterxml.jackson.databind.jsontype.ext;

import org.junit.Test;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
Expand All @@ -11,6 +9,8 @@
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

// for [databind#2404]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;

import com.fasterxml.jackson.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.*;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -116,13 +115,13 @@ public void testPolymorphicWithContainer() throws Exception
Container1 c1 = new Container1();
c1.setAnimal(dog);
String s1 = mapper.writeValueAsString(c1);
Assert.assertTrue("polymorphic type info is kept (1)", s1
.indexOf("\"object-type\":\"doggy\"") >= 0);
assertTrue(s1.indexOf("\"object-type\":\"doggy\"") >= 0,
"polymorphic type info is kept (1)");
Container2<Animal> c2 = new Container2<Animal>();
c2.setAnimal(dog);
String s2 = mapper.writeValueAsString(c2);
Assert.assertTrue("polymorphic type info is kept (2)", s2
.indexOf("\"object-type\":\"doggy\"") >= 0);
assertTrue(s2.indexOf("\"object-type\":\"doggy\"") >= 0,
"polymorphic type info is kept (2)");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.util.RawValue;

import org.junit.jupiter.api.Test;

import static java.util.Arrays.asList;
import static org.junit.Assert.*;

import static org.junit.jupiter.api.Assertions.*;

/**
* Additional tests for {@link ArrayNode} container class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ private void _assertNullTree(TreeNode n) {
}

private void _assertMissing(JsonNode n) {
assertNotNull("Should not get `null` but `MissingNode`", n);
assertNotNull(n, "Should not get `null` but `MissingNode`");
if (!n.isMissingNode()) {
fail("Should get `MissingNode` but got: "+n.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import org.junit.Assert;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.*;
Expand Down Expand Up @@ -272,9 +271,9 @@ public void testIssue709() throws Exception
Issue709Bean resultFromConvert = MAPPER.convertValue(node, Issue709Bean.class);

// all methods should work equally well:
Assert.assertArrayEquals(inputData, resultFromString.data);
Assert.assertArrayEquals(inputData, resultFromConvert.data);
Assert.assertArrayEquals(inputData, result.data);
assertArrayEquals(inputData, resultFromString.data);
assertArrayEquals(inputData, resultFromConvert.data);
assertArrayEquals(inputData, result.data);
}

@Test
Expand Down Expand Up @@ -328,7 +327,7 @@ public void testConversionOfPojos() throws Exception

// then via conversions: should become JSON Object
JsonNode tree = MAPPER.valueToTree(input);
assertTrue("Expected Object, got "+tree.getNodeType(), tree.isObject());
assertTrue(tree.isObject(), "Expected Object, got "+tree.getNodeType());
assertEquals(EXP, MAPPER.writeValueAsString(tree));
}

Expand All @@ -345,7 +344,8 @@ public void testConversionOfTrees() throws Exception

// then via conversions: should become JSON Object
JsonNode tree = MAPPER.valueToTree(input);
assertTrue("Expected Object, got "+tree.getNodeType(), tree.isBoolean());
assertTrue(tree.isBoolean(),
"Expected Object, got "+tree.getNodeType());
assertEquals(EXP, MAPPER.writeValueAsString(tree));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonGenerator;
Expand Down Expand Up @@ -52,6 +51,6 @@ public void testPolyCustomKeySerializer() throws Exception

final ObjectWriter writer = mapper.writerFor(new TypeReference<Map<CustomKey,String>>() { });
String json = writer.writeValueAsString(map);
Assert.assertEquals("[\"java.util.HashMap\",{\"foo,1\":\"bar\"}]", json);
assertEquals("[\"java.util.HashMap\",{\"foo,1\":\"bar\"}]", json);
}
}
Loading

0 comments on commit a2a7db7

Please sign in to comment.