forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert Jackson version to 2.8.11 and add JacksonSerializer tests (Azu…
- Loading branch information
Dan Schulte
authored
Jan 2, 2018
1 parent
430580b
commit 91dc54e
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
client-runtime/src/test/java/com/microsoft/rest/v2/serializer/JacksonAdapterTests.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,58 @@ | ||
package com.microsoft.rest.v2.serializer; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class JacksonAdapterTests { | ||
@Test | ||
public void emptyMap() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{}", serializer.serialize(map)); | ||
} | ||
|
||
@Test | ||
public void mapWithNullKey() { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put(null, null); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
try { | ||
serializer.serialize(map); | ||
fail(); | ||
} | ||
catch (Exception e) { | ||
assertEquals(JsonMappingException.class, e.getClass()); | ||
assertTrue(e.getMessage().contains("Null key for a Map not allowed in JSON")); | ||
} | ||
} | ||
|
||
@Test | ||
public void mapWithEmptyKeyAndNullValue() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put("", null); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{\"\":null}", serializer.serialize(map)); | ||
} | ||
|
||
@Test | ||
public void mapWithEmptyKeyAndEmptyValue() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put("", ""); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{\"\":\"\"}", serializer.serialize(map)); | ||
} | ||
|
||
@Test | ||
public void mapWithEmptyKeyAndNonEmptyValue() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put("", "test"); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{\"\":\"test\"}", serializer.serialize(map)); | ||
} | ||
} |
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