-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: data format did not correctly serialize JSON array.
- Loading branch information
lorenzo
committed
Aug 19, 2020
1 parent
a459832
commit 28c1561
Showing
3 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/com/reedelk/openapi/commons/DataFormatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.reedelk.openapi.commons; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals; | ||
import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT; | ||
|
||
class DataFormatTest { | ||
|
||
@Test | ||
void shouldCorrectlyDumpLinkedHashMapObject() { | ||
// Given | ||
Map<String, Object> shipment = new LinkedHashMap<>(); | ||
shipment.put("id", "aabbcc"); | ||
shipment.put("details", "FedEx"); | ||
|
||
// When | ||
String jsonData = DataFormat.JSON.dump(shipment); | ||
|
||
// Then | ||
assertEquals("{\n" + | ||
" \"details\": \"FedEx\",\n" + | ||
" \"id\": \"aabbcc\"\n" + | ||
"}", jsonData, STRICT); | ||
} | ||
|
||
@Test | ||
void shouldCorrectlyDumpLinkedHashMapObjectWithNestedMap() { | ||
// Given | ||
Map<String, Object> shipmentDetails = new LinkedHashMap<>(); | ||
shipmentDetails.put("carrier", "FedEx"); | ||
shipmentDetails.put("time", "Morning"); | ||
|
||
Map<String, Object> shipment = new LinkedHashMap<>(); | ||
shipment.put("id", "aabbcc"); | ||
shipment.put("details", shipmentDetails); | ||
|
||
// When | ||
String jsonData = DataFormat.JSON.dump(shipment); | ||
|
||
// Then | ||
assertEquals("{\n" + | ||
" \"details\": {\n" + | ||
" \"carrier\": \"FedEx\",\n" + | ||
" \"time\": \"Morning\"\n" + | ||
" },\n" + | ||
" \"id\": \"aabbcc\"\n" + | ||
"}", jsonData, STRICT); | ||
} | ||
|
||
@Test | ||
void shouldCorrectlyDumpArrayAsJson() { | ||
// Given | ||
Map<String, Object> shipment1Details = new LinkedHashMap<>(); | ||
shipment1Details.put("carrier", "FedEx"); | ||
|
||
Map<String, Object> shipment1 = new LinkedHashMap<>(); | ||
shipment1.put("id", "aabbcc"); | ||
shipment1.put("details", shipment1Details); | ||
|
||
List<Map<String, Object>> shipments = new ArrayList<>(); | ||
shipments.add(shipment1); | ||
|
||
// When | ||
String jsonData = DataFormat.JSON.dump(shipments); | ||
|
||
// Then | ||
assertEquals("[{\n" + | ||
" \"details\": {\"carrier\": \"FedEx\"},\n" + | ||
" \"id\": \"aabbcc\"\n" + | ||
"}]", jsonData, STRICT); | ||
} | ||
} |