Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 7, 2024
2 parents 8d5b19d + 4b8244c commit dc1f2d0
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 24 deletions.
16 changes: 15 additions & 1 deletion src/test/java/com/fasterxml/jackson/annotation/FormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import com.fasterxml.jackson.annotation.JsonFormat.Feature;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;

import org.junit.jupiter.api.Test;

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

/**
* Tests to verify that it is possibly to merge {@link JsonFormat.Value}
* instances for overrides.
*/
public class FormatTest extends TestBase
public class FormatTest
{
private final JsonFormat.Value EMPTY = JsonFormat.Value.empty();

@JsonFormat(shape=JsonFormat.Shape.BOOLEAN, pattern="xyz", timezone="bogus")
private final static class Bogus { }

@Test
public void testEmptyInstanceDefaults() {
JsonFormat.Value empty = JsonFormat.Value.empty();
for (Feature f : Feature.values()) {
Expand All @@ -28,6 +33,7 @@ public void testEmptyInstanceDefaults() {
assertFalse(empty.isLenient());
}

@Test
public void testEquality() {
JsonFormat.Value v1 = JsonFormat.Value.forShape(Shape.BOOLEAN);

Expand All @@ -37,13 +43,15 @@ public void testEquality() {
assertFalse(v1.equals(v1.withoutFeature(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)));
}

@Test
public void testToString() {
assertEquals("JsonFormat.Value(pattern=,shape=STRING,lenient=null,locale=null,timezone=null,features=EMPTY)",
JsonFormat.Value.forShape(JsonFormat.Shape.STRING).toString());
assertEquals("JsonFormat.Value(pattern=[.],shape=ANY,lenient=null,locale=null,timezone=null,features=EMPTY)",
JsonFormat.Value.forPattern("[.]").toString());
}

@Test
public void testFromAnnotation()
{
JsonFormat ann = Bogus.class.getAnnotation(JsonFormat.class);
Expand All @@ -57,6 +65,7 @@ public void testFromAnnotation()
assertSame(EMPTY, JsonFormat.Value.from(null));
}

@Test
public void testSimpleMerge()
{
// Start with an empty instance
Expand Down Expand Up @@ -114,6 +123,7 @@ public void testSimpleMerge()
assertFalse(merged.hasTimeZone());
}

@Test
public void testMultiMerge()
{
final String TEST_PATTERN = "format-string"; // not parsed, usage varies
Expand All @@ -131,6 +141,7 @@ public void testMultiMerge()
/**********************************************************
*/

@Test
public void testLeniency() {
JsonFormat.Value empty = JsonFormat.Value.empty();
assertFalse(empty.hasLenient());
Expand Down Expand Up @@ -169,6 +180,7 @@ public void testLeniency() {
assertFalse(dunno.equals(lenient));
}

@Test
public void testCaseInsensitiveValues() {
JsonFormat.Value empty = JsonFormat.Value.empty();
assertNull(empty.getFeature(Feature.ACCEPT_CASE_INSENSITIVE_VALUES));
Expand All @@ -180,6 +192,7 @@ public void testCaseInsensitiveValues() {
assertFalse(sensitive.getFeature(Feature.ACCEPT_CASE_INSENSITIVE_VALUES));
}

@Test
public void testShape() {
assertFalse(JsonFormat.Shape.STRING.isNumeric());
assertFalse(JsonFormat.Shape.STRING.isStructured());
Expand All @@ -192,6 +205,7 @@ public void testShape() {
assertTrue(JsonFormat.Shape.OBJECT.isStructured());
}

@Test
public void testFeatures() {
JsonFormat.Features f1 = JsonFormat.Features.empty();
JsonFormat.Features f2 = f1.with(Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/fasterxml/jackson/annotation/IncludeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.fasterxml.jackson.annotation.JsonInclude.Include;

import org.junit.jupiter.api.Test;

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

/**
* Tests to verify that it is possibly to merge {@link JsonInclude.Value}
* instances for overrides
*/
public class IncludeTest extends TestBase
public class IncludeTest
{
private final JsonInclude.Value EMPTY = JsonInclude.Value.empty();

Expand All @@ -17,6 +21,7 @@ private final static class Bogus { }
content=JsonInclude.Include.CUSTOM, contentFilter=Long.class)
private final static class Custom { }

@Test
public void testEquality() {
assertTrue(EMPTY.equals(EMPTY));

Expand All @@ -33,6 +38,7 @@ public void testEquality() {
assertFalse(v3.equals(v2));
}

@Test
public void testFromAnnotation()
{
JsonInclude ann = Bogus.class.getAnnotation(JsonInclude.class);
Expand All @@ -41,6 +47,7 @@ public void testFromAnnotation()
assertEquals(Include.NON_DEFAULT, v.getContentInclusion());
}

@Test
public void testFromAnnotationWithCustom()
{
JsonInclude ann = Custom.class.getAnnotation(JsonInclude.class);
Expand All @@ -55,6 +62,7 @@ public void testFromAnnotationWithCustom()
v.toString());
}

@Test
public void testStdOverrides() {
assertEquals("JsonInclude.Value(value=NON_ABSENT,content=USE_DEFAULTS)",
JsonInclude.Value.construct(Include.NON_ABSENT, null).toString());
Expand All @@ -66,6 +74,7 @@ public void testStdOverrides() {
assertFalse(EMPTY.equals(""));
}

@Test
public void testSimpleMerge()
{
JsonInclude.Value empty = JsonInclude.Value.empty();
Expand Down Expand Up @@ -100,6 +109,7 @@ public void testSimpleMerge()
}

// for [annotations#76]
@Test
public void testContentMerge76()
{
JsonInclude.Value v1 = JsonInclude.Value.empty()
Expand All @@ -119,6 +129,7 @@ public void testContentMerge76()
assertEquals(JsonInclude.Include.NON_ABSENT, v21.getValueInclusion());
}

@Test
public void testFilters()
{
JsonInclude.Value empty = JsonInclude.Value.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.fasterxml.jackson.annotation;

public class JacksonInjectTest extends TestBase
import org.junit.jupiter.api.Test;

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

public class JacksonInjectTest
{
private final static class Bogus {
@JacksonInject(value="inject", useInput=OptBoolean.FALSE)
Expand All @@ -12,6 +16,7 @@ private final static class Bogus {

private final JacksonInject.Value EMPTY = JacksonInject.Value.empty();

@Test
public void testEmpty()
{
assertNull(EMPTY.getId());
Expand All @@ -24,6 +29,7 @@ public void testEmpty()
assertSame(EMPTY, JacksonInject.Value.construct("", null));
}

@Test
public void testFromAnnotation() throws Exception
{
assertSame(EMPTY, JacksonInject.Value.from(null)); // legal
Expand All @@ -42,6 +48,7 @@ public void testFromAnnotation() throws Exception
assertSame(EMPTY, v);
}

@Test
public void testStdMethods() {
assertEquals("JacksonInject.Value(id=null,useInput=null)",
EMPTY.toString());
Expand All @@ -54,6 +61,7 @@ public void testStdMethods() {
assertFalse(EMPTY.equals("xyz"));
}

@Test
public void testFactories() throws Exception
{
JacksonInject.Value v = EMPTY.withId("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import java.util.*;

import org.junit.jupiter.api.Test;

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

/**
* Tests to verify that it is possibly to merge {@link JsonIgnoreProperties.Value}
* instances for overrides
*/
public class JsonIgnorePropertiesTest extends TestBase
public class JsonIgnorePropertiesTest
{
@JsonIgnoreProperties(value={ "foo", "bar" }, ignoreUnknown=true)
private final static class Bogus {
}

private final JsonIgnoreProperties.Value EMPTY = JsonIgnoreProperties.Value.empty();

@Test
public void testEmpty() {
// ok to try to create from null; gives empty
assertSame(EMPTY, JsonIgnoreProperties.Value.from(null));
Expand All @@ -23,6 +28,7 @@ public void testEmpty() {
assertFalse(EMPTY.getAllowSetters());
}

@Test
public void testEquality() {
assertEquals(EMPTY, EMPTY);

Expand All @@ -35,6 +41,7 @@ public void testEquality() {
assertFalse(v.equals(EMPTY));
}

@Test
public void testFromAnnotation() throws Exception
{
JsonIgnoreProperties.Value v = JsonIgnoreProperties.Value.from(
Expand All @@ -48,6 +55,7 @@ public void testFromAnnotation() throws Exception
assertEquals(_set("foo", "bar"), ign);
}

@Test
public void testFactories() {
assertSame(EMPTY, JsonIgnoreProperties.Value.forIgnoreUnknown(false));
assertSame(EMPTY, JsonIgnoreProperties.Value.forIgnoredProperties());
Expand All @@ -71,6 +79,7 @@ public void testFactories() {
assertEquals(_set("a", "b"), vdeser.findIgnoredForSerialization());
}

@Test
public void testMutantFactories()
{
assertEquals(2, EMPTY.withIgnored("a", "b").getIgnored().size());
Expand All @@ -89,6 +98,7 @@ public void testMutantFactories()
assertFalse(EMPTY.withoutMerge().getMerge());
}

@Test
public void testSimpleMerge()
{
JsonIgnoreProperties.Value v1 = EMPTY.withIgnoreUnknown().withAllowGetters();
Expand Down Expand Up @@ -117,6 +127,7 @@ public void testSimpleMerge()
assertSame(v2b, v2b.withOverrides(EMPTY));
}

@Test
public void testMergeIgnoreProperties()
{
JsonIgnoreProperties.Value v1 = EMPTY.withIgnored("a");
Expand All @@ -131,6 +142,7 @@ public void testMergeIgnoreProperties()
assertTrue(all.contains("c"));
}

@Test
public void testToString() {
assertEquals(
"JsonIgnoreProperties.Value(ignored=[],ignoreUnknown=false,allowGetters=false,allowSetters=true,merge=true)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.fasterxml.jackson.annotation;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.*;

import org.junit.jupiter.api.Test;

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

/**
* Tests to verify that it is possibly to merge {@link JsonIncludeProperties.Value}
* instances for overrides
*/
public class JsonIncludePropertiesTest extends TestBase
public class JsonIncludePropertiesTest
{
@JsonIncludeProperties(value = {"foo", "bar"})
private final static class Bogus
Expand All @@ -18,6 +19,7 @@ private final static class Bogus

private final JsonIncludeProperties.Value ALL = JsonIncludeProperties.Value.all();

@Test
public void testAll()
{
assertSame(ALL, JsonIncludeProperties.Value.from(null));
Expand All @@ -27,6 +29,7 @@ public void testAll()
assertEquals(0, ALL.hashCode());
}

@Test
public void testFromAnnotation()
{
JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
Expand All @@ -41,6 +44,7 @@ public void testFromAnnotation()
assertEquals(v, JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class)));
}

@Test
public void testWithOverridesAll() {
JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
v = v.withOverrides(ALL);
Expand All @@ -49,13 +53,15 @@ public void testWithOverridesAll() {
assertEquals(_set("foo", "bar"), included);
}

@Test
public void testWithOverridesEmpty() {
JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
v = v.withOverrides(new JsonIncludeProperties.Value(Collections.<String>emptySet()));
Set<String> included = v.getIncluded();
assertEquals(0, included.size());
}

@Test
public void testWithOverridesMerge() {
JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
v = v.withOverrides(new JsonIncludeProperties.Value(_set("foo")));
Expand Down
Loading

0 comments on commit dc1f2d0

Please sign in to comment.