1919import com .fasterxml .jackson .databind .ObjectMapper ;
2020import com .fasterxml .jackson .databind .node .ObjectNode ;
2121
22- public class JacksonNodeOperationTest {
22+ public class NodeOperationTest {
2323 private static ObjectMapper mapper = new ObjectMapper ();
2424
2525 @ Test
2626 public void giveAnObject_whenConvertingIntoANode_thenCorrect () {
27- MyBean fromValue = new MyBean (2016 , "baeldung.com" );
27+ final NodeBean fromValue = new NodeBean (2016 , "baeldung.com" );
2828
29- JsonNode node = mapper .valueToTree (fromValue );
29+ final JsonNode node = mapper .valueToTree (fromValue );
3030
3131 assertEquals (2016 , node .get ("id" ).intValue ());
3232 assertEquals ("baeldung.com" , node .get ("name" ).textValue ());
@@ -35,9 +35,9 @@ public void giveAnObject_whenConvertingIntoANode_thenCorrect() {
3535 @ Test
3636 public void givenANode_whenWritingOutAsAJsonString_thenCorrect () throws IOException {
3737 final String pathToTestFile = "node_to_json_test.json" ;
38- char [] characterBuffer = new char [50 ];
38+ final char [] characterBuffer = new char [50 ];
3939
40- JsonNode node = mapper .createObjectNode ();
40+ final JsonNode node = mapper .createObjectNode ();
4141 ((ObjectNode ) node ).put ("id" , 2016 );
4242 ((ObjectNode ) node ).put ("name" , "baeldung.com" );
4343
@@ -48,7 +48,7 @@ public void givenANode_whenWritingOutAsAJsonString_thenCorrect() throws IOExcept
4848 try (FileReader inputStreamForAssertion = new FileReader (pathToTestFile )) {
4949 inputStreamForAssertion .read (characterBuffer );
5050 }
51- String textContentOfTestFile = new String (characterBuffer );
51+ final String textContentOfTestFile = new String (characterBuffer );
5252
5353 assertThat (textContentOfTestFile , containsString ("2016" ));
5454 assertThat (textContentOfTestFile , containsString ("baeldung.com" ));
@@ -58,20 +58,20 @@ public void givenANode_whenWritingOutAsAJsonString_thenCorrect() throws IOExcept
5858
5959 @ Test
6060 public void givenANode_whenConvertingIntoAnObject_thenCorrect () throws JsonProcessingException {
61- JsonNode node = mapper .createObjectNode ();
61+ final JsonNode node = mapper .createObjectNode ();
6262 ((ObjectNode ) node ).put ("id" , 2016 );
6363 ((ObjectNode ) node ).put ("name" , "baeldung.com" );
6464
65- MyBean toValue = mapper .treeToValue (node , MyBean .class );
65+ final NodeBean toValue = mapper .treeToValue (node , NodeBean .class );
6666
6767 assertEquals (2016 , toValue .getId ());
6868 assertEquals ("baeldung.com" , toValue .getName ());
6969 }
7070
7171 @ Test
7272 public void givenANode_whenAddingIntoATree_thenCorrect () throws IOException {
73- JsonNode rootNode = ExampleStructure .getExampleRoot ();
74- ObjectNode addedNode = ((ObjectNode ) rootNode ).putObject ("address" );
73+ final JsonNode rootNode = ExampleStructure .getExampleRoot ();
74+ final ObjectNode addedNode = ((ObjectNode ) rootNode ).putObject ("address" );
7575 addedNode .put ("city" , "Seattle" ).put ("state" , "Washington" ).put ("country" , "United States" );
7676
7777 assertFalse (rootNode .path ("address" ).isMissingNode ());
@@ -82,10 +82,10 @@ public void givenANode_whenAddingIntoATree_thenCorrect() throws IOException {
8282
8383 @ Test
8484 public void givenANode_whenModifyingIt_thenCorrect () throws IOException {
85- String newString = "{\" nick\" : \" cowtowncoder\" }" ;
86- JsonNode newNode = mapper .readTree (newString );
85+ final String newString = "{\" nick\" : \" cowtowncoder\" }" ;
86+ final JsonNode newNode = mapper .readTree (newString );
8787
88- JsonNode rootNode = ExampleStructure .getExampleRoot ();
88+ final JsonNode rootNode = ExampleStructure .getExampleRoot ();
8989 ((ObjectNode ) rootNode ).set ("name" , newNode );
9090
9191 assertFalse (rootNode .path ("name" ).path ("nick" ).isMissingNode ());
@@ -94,7 +94,7 @@ public void givenANode_whenModifyingIt_thenCorrect() throws IOException {
9494
9595 @ Test
9696 public void givenANode_whenRemovingFromATree_thenCorrect () throws IOException {
97- JsonNode rootNode = ExampleStructure .getExampleRoot ();
97+ final JsonNode rootNode = ExampleStructure .getExampleRoot ();
9898 ((ObjectNode ) rootNode ).remove ("company" );
9999
100100 assertTrue (rootNode .path ("company" ).isMissingNode ());
0 commit comments