Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate /convert tests to JUnit 5 #4307

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.fasterxml.jackson.databind.convert;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.type.LogicalType;

public class CoerceBoolToStringTest extends BaseMapTest
import static org.junit.jupiter.api.Assertions.*;

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;

public class CoerceBoolToStringTest
{
private final ObjectMapper DEFAULT_MAPPER = newJsonMapper();

Expand All @@ -33,16 +38,19 @@ public class CoerceBoolToStringTest extends BaseMapTest
cfg.setCoercion(CoercionInputShape.Boolean, CoercionAction.AsEmpty))
.build();

@Test
public void testDefaultBooleanToStringCoercion() throws JsonProcessingException
{
assertSuccessfulBooleanToStringCoercionWith(DEFAULT_MAPPER);
}

@Test
public void testCoerceConfigToConvert() throws JsonProcessingException
{
assertSuccessfulBooleanToStringCoercionWith(MAPPER_TRY_CONVERT);
}

@Test
public void testCoerceConfigToNull() throws JsonProcessingException
{
assertNull(MAPPER_TO_NULL.readValue("true", String.class));
Expand All @@ -53,6 +61,7 @@ public void testCoerceConfigToNull() throws JsonProcessingException
assertNull(arr[0]);
}

@Test
public void testCoerceConfigToEmpty() throws JsonProcessingException
{
assertEquals("", MAPPER_TO_EMPTY.readValue("true", String.class));
Expand All @@ -63,6 +72,7 @@ public void testCoerceConfigToEmpty() throws JsonProcessingException
assertEquals("", arr[0]);
}

@Test
public void testCoerceConfigToFail() throws JsonProcessingException
{
_verifyCoerceFail(MAPPER_TO_FAIL, String.class, "true");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.fasterxml.jackson.databind.convert;

import java.util.*;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;

public class CoerceContainersTest extends BaseMapTest
import static org.junit.jupiter.api.Assertions.*;

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;

public class CoerceContainersTest
{
private final String JSON_EMPTY = q("");

Expand All @@ -25,6 +34,7 @@ public class CoerceContainersTest extends BaseMapTest
/********************************************************
*/

@Test
public void testScalarCollections() throws Exception
{
final JavaType listType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -48,6 +58,7 @@ public void testScalarCollections() throws Exception
assertEquals(0, result.size());
}

@Test
public void testStringCollections() throws Exception
{
final JavaType listType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -64,6 +75,7 @@ public void testStringCollections() throws Exception
/********************************************************
*/

@Test
public void testScalarMap() throws Exception
{
final JavaType mapType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -74,6 +86,7 @@ public void testScalarMap() throws Exception
assertEquals(0, result.size());
}

@Test
public void testEnumMap() throws Exception
{
final JavaType mapType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -90,6 +103,7 @@ public void testEnumMap() throws Exception
/********************************************************
*/

@Test
public void testObjectArray() throws Exception
{
final JavaType arrayType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -100,6 +114,7 @@ public void testObjectArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testStringArray() throws Exception
{
final JavaType arrayType = VANILLA_MAPPER.getTypeFactory()
Expand All @@ -110,6 +125,7 @@ public void testStringArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testBooleanArray() throws Exception
{
_verifyNoCoercion(boolean[].class);
Expand All @@ -118,6 +134,7 @@ public void testBooleanArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testIntArray() throws Exception
{
_verifyNoCoercion(int[].class);
Expand All @@ -126,6 +143,7 @@ public void testIntArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testLongArray() throws Exception
{
_verifyNoCoercion(long[].class);
Expand All @@ -134,6 +152,7 @@ public void testLongArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testFloatArray() throws Exception
{
_verifyNoCoercion(float[].class);
Expand All @@ -142,6 +161,7 @@ public void testFloatArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testDoubleArray() throws Exception
{
_verifyNoCoercion(double[].class);
Expand All @@ -150,6 +170,7 @@ public void testDoubleArray() throws Exception
assertEquals(0, result.length);
}

@Test
public void testPOJOArray() throws Exception
{
_verifyNoCoercion(StringWrapper[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
import java.net.URL;
import java.util.*;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.type.LogicalType;

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

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.*;

/**
* Tests to verify implementation of [databind#540]; also for
* follow up work of:
*
* - [databind#994]
*/
public class CoerceEmptyArrayTest extends BaseMapTest
public class CoerceEmptyArrayTest
{
private final ObjectMapper DEFAULT_MAPPER = sharedMapper();
private final ObjectReader DEFAULT_READER = DEFAULT_MAPPER.reader();
Expand Down Expand Up @@ -64,6 +71,7 @@ public boolean equals(Object o) {
/**********************************************************
*/

@Test
public void testSettings() {
assertFalse(DEFAULT_MAPPER.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT));
assertFalse(DEFAULT_READER.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT));
Expand All @@ -77,6 +85,7 @@ public void testSettings() {
*/

// [databind#540]
@Test
public void testPOJOFromEmptyArray() throws Exception
{
final Class<?> targetType = Bean.class;
Expand Down Expand Up @@ -113,6 +122,7 @@ public void testPOJOFromEmptyArray() throws Exception
/**********************************************************
*/

@Test
public void testMapFromEmptyArray() throws Exception
{
final Class<?> targetType = Map.class;
Expand All @@ -129,10 +139,11 @@ public void testMapFromEmptyArray() throws Exception
// assume overrides work ok since POJOs test it
}

@Test
public void testEnumMapFromEmptyArray() throws Exception
{
final JavaType targetType = DEFAULT_READER.getTypeFactory()
.constructType(new TypeReference<EnumMap<ABC,String>>() { });
.constructType(new TypeReference<EnumMap<DatabindTestUtil.ABC,String>>() { });

assertNull(MAPPER_TO_NULL.readerFor(targetType).readValue(EMPTY_ARRAY));

Expand All @@ -147,6 +158,7 @@ public void testEnumMapFromEmptyArray() throws Exception
/**********************************************************
*/

@Test
public void testNumbersFromEmptyArray() throws Exception
{
for (Class<?> targetType : new Class<?>[] {
Expand Down Expand Up @@ -180,6 +192,7 @@ public void testNumbersFromEmptyArray() throws Exception
_verifyToEmptyCoercion(MAPPER_TO_EMPTY, BigDecimal.class, new BigDecimal(BigInteger.ZERO));
}

@Test
public void testOtherScalarsFromEmptyArray() throws Exception
{
for (Class<?> targetType : new Class<?>[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.fasterxml.jackson.databind.convert;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.*;

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

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.a2q;
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;

// [databind#3234]
public class CoerceEmptyToInt3234Test extends BaseMapTest
public class CoerceEmptyToInt3234Test
{
static class BasicIntWrapper {
public int value = 13;
Expand All @@ -24,12 +31,14 @@ static class BasicDoubleWrapper {

// // // Ints

@Test
public void testSimpleIntFromEmpty() throws Exception
{
BasicIntWrapper w = READER_INT_BASIC.readValue(a2q("{'value':''}"));
assertEquals(0, w.value);
}

@Test
public void testSimpleIntFromBlank() throws Exception
{
BasicIntWrapper w = READER_INT_BASIC.readValue(a2q("{'value':' '}"));
Expand All @@ -38,12 +47,14 @@ public void testSimpleIntFromBlank() throws Exception

// // // Long

@Test
public void testSimpleLongFromEmpty() throws Exception
{
BasicLongWrapper w = READER_LONG_BASIC.readValue(a2q("{'value':''}"));
assertEquals(0L, w.value);
}

@Test
public void testSimpleLongFromBlank() throws Exception
{
BasicLongWrapper w = READER_LONG_BASIC.readValue(a2q("{'value':' '}"));
Expand All @@ -52,12 +63,14 @@ public void testSimpleLongFromBlank() throws Exception

// // // Double

@Test
public void testSimpleDoublegFromEmpty() throws Exception
{
BasicDoubleWrapper w = READER_DOUBLE_BASIC.readValue(a2q("{'value':''}"));
assertEquals((double) 0, w.value);
}

@Test
public void testSimpleDoubleFromBlank() throws Exception
{
BasicDoubleWrapper w = READER_DOUBLE_BASIC.readValue(a2q("{'value':' '}"));
Expand Down
Loading