Skip to content

Commit

Permalink
Test streamlining
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 29, 2023
1 parent 213f722 commit 5cece09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.fasterxml.jackson.databind.deser.filter;

import java.beans.ConstructorProperties;
import java.io.IOException;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ReadOnlyDeser1890Test
extends BaseMapTest
{
public static class PersonAnnotations {
// [databind#95]
@JsonIgnoreProperties(value={ "computed" }, allowGetters=true)
static class ReadOnly95Bean
{
public int value = 3;

public int getComputed() { return 32; }
}

// [databind#1890]
static class PersonAnnotations {
public String name;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private TestEnum testEnum = TestEnum.DEFAULT;
Expand All @@ -30,9 +40,9 @@ public TestEnum getTestEnum() {
public void setTestEnum(TestEnum testEnum) {
this.testEnum = testEnum;
}
}
}

public static class Person {
static class Person {
public String name;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private TestEnum testEnum = TestEnum.DEFAULT;
Expand Down Expand Up @@ -63,30 +73,43 @@ enum TestEnum{
/**********************************************************
*/

private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = newJsonMapper();

// [databind#95]
public void testReadOnlyProps95() throws Exception
{
ObjectMapper m = new ObjectMapper();
String json = m.writeValueAsString(new ReadOnly95Bean());
if (json.indexOf("computed") < 0) {
fail("Should have property 'computed', didn't: "+json);
}
ReadOnly95Bean bean = m.readValue(json, ReadOnly95Bean.class);
assertNotNull(bean);
}

public void testDeserializeAnnotationsOneField() throws IOException {
// [databind#1890]
public void testDeserializeAnnotationsOneField() throws Exception {
PersonAnnotations person = MAPPER.readValue("{\"testEnum\":\"\"}", PersonAnnotations.class);
// can not remain as is, so becomes `null`
assertEquals(null, person.getTestEnum());
assertNull(person.name);
}

public void testDeserializeAnnotationsTwoFields() throws IOException {
public void testDeserializeAnnotationsTwoFields() throws Exception {
PersonAnnotations person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}",
PersonAnnotations.class);
// can not remain as is, so becomes `null`
assertEquals(null, person.getTestEnum());
assertEquals("changyong", person.name);
}

public void testDeserializeOneField() throws IOException {
public void testDeserializeOneField() throws Exception {
Person person = MAPPER.readValue("{\"testEnum\":\"\"}", Person.class);
assertEquals(TestEnum.DEFAULT, person.getTestEnum());
assertNull(person.name);
}

public void testDeserializeTwoFields() throws IOException {
public void testDeserializeTwoFields() throws Exception {
Person person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}",
Person.class);
assertEquals(TestEnum.DEFAULT, person.getTestEnum());
Expand Down

This file was deleted.

0 comments on commit 5cece09

Please sign in to comment.