Skip to content

Commit

Permalink
minor refactoring of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 12, 2016
1 parent df523d6 commit 6875566
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fasterxml.jackson.databind.creators;

import java.beans.ConstructorProperties;

import com.fasterxml.jackson.databind.*;

public class CreatorPropertiesTest extends BaseMapTest
{
static class Issue905Bean {
// 08-Nov-2015, tatu: Note that in real code we would most likely use same
// names for properties; but here we use different name on purpose to
// ensure that Jackson has no way of binding JSON properties "x" and "y"
// using any other mechanism than via `@ConstructorProperties` annotation
public int _x, _y;

@ConstructorProperties({"x", "y"})
// Same as above; use differing local parameter names so that parameter name
// introspection can not be used as the source of property names.
public Issue905Bean(int a, int b) {
_x = a;
_y = b;
}
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();

// [databind#905]
public void testCreatorPropertiesAnnotation() throws Exception
{
Issue905Bean b = MAPPER.readValue(aposToQuotes("{'y':3,'x':2}"),
Issue905Bean.class);
assertEquals(2, b._x);
assertEquals(3, b._y);
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public BeanFor438(@JsonProperty("name") String s) {
} }
} }


// For [JACKSON-465]
static class MapBean static class MapBean
{ {
protected Map<String,Long> map; protected Map<String,Long> map;
Expand Down Expand Up @@ -122,7 +121,6 @@ static class BustedCtor {
} }
} }


// As per [JACKSON-575]
static class IgnoredCtor static class IgnoredCtor
{ {
@JsonIgnore @JsonIgnore
Expand Down Expand Up @@ -162,22 +160,6 @@ public Issue700Bean(@JsonProperty("item") String item) { }
public String getItem() { return null; } public String getItem() { return null; }
} }


static class Issue905Bean {
// 08-Nov-2015, tatu: Note that in real code we would most likely use same
// names for properties; but here we use different name on purpose to
// ensure that Jackson has no way of binding JSON properties "x" and "y"
// using any other mechanism than via `@ConstructorProperties` annotation
public int _x, _y;

@ConstructorProperties({"x", "y"})
// Same as above; use differing local parameter names so that parameter name
// introspection can not be used as the source of property names.
public Issue905Bean(int a, int b) {
_x = a;
_y = b;
}
}

/* /*
/********************************************************** /**********************************************************
/* Test methods /* Test methods
Expand Down Expand Up @@ -313,13 +295,4 @@ public void testCreatorProperties() throws Exception
Issue700Bean value = MAPPER.readValue("{ \"item\" : \"foo\" }", Issue700Bean.class); Issue700Bean value = MAPPER.readValue("{ \"item\" : \"foo\" }", Issue700Bean.class);
assertNotNull(value); assertNotNull(value);
} }

// [databind#905]
public void testCreatorPropertiesAnnotation() throws Exception
{
Issue905Bean b = MAPPER.readValue(aposToQuotes("{'y':3,'x':2}"),
Issue905Bean.class);
assertEquals(2, b._x);
assertEquals(3, b._y);
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static class Bean1124


public void addAdditionalProperty(String key, String value) { public void addAdditionalProperty(String key, String value) {
if (additionalProperties == null) { if (additionalProperties == null) {
additionalProperties = new HashMap<>(); additionalProperties = new HashMap<String,String>();
} }
additionalProperties.put(key,value); additionalProperties.put(key,value);
} }
Expand Down

0 comments on commit 6875566

Please sign in to comment.