-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrading jackson from 2.8.11 to 2.9.6
- Loading branch information
Showing
2 changed files
with
23 additions
and
21 deletions.
There are no files selected for viewing
42 changes: 22 additions & 20 deletions
42
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 |
---|---|---|
@@ -1,58 +1,60 @@ | ||
package com.microsoft.rest.v2.serializer; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.microsoft.rest.v2.protocol.SerializerEncoding; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
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)); | ||
assertEquals("{}", serializer.serialize(map, SerializerEncoding.JSON)); | ||
} | ||
|
||
@Test | ||
public void mapWithNullKey() { | ||
public void mapWithNullKey() throws IOException { | ||
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")); | ||
} | ||
assertEquals("{}", serializer.serialize(map, SerializerEncoding.JSON)); | ||
} | ||
|
||
@Test | ||
public void mapWithEmptyKeyAndNullValue() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put("", null); | ||
final MapHolder mapHolder = new MapHolder(); | ||
mapHolder.map = new HashMap<>(); | ||
mapHolder.map.put("", null); | ||
|
||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{\"\":null}", serializer.serialize(map)); | ||
assertEquals("{\"map\":{\"\":null}}", serializer.serialize(mapHolder, SerializerEncoding.JSON)); | ||
} | ||
|
||
@Test | ||
public void mapWithEmptyKeyAndEmptyValue() throws IOException { | ||
final Map<String,String> map = new HashMap<>(); | ||
map.put("", ""); | ||
final MapHolder mapHolder = new MapHolder(); | ||
mapHolder.map = new HashMap<>(); | ||
mapHolder.map.put("", ""); | ||
final JacksonAdapter serializer = new JacksonAdapter(); | ||
assertEquals("{\"\":\"\"}", serializer.serialize(map)); | ||
assertEquals("{\"map\":{\"\":\"\"}}", serializer.serialize(mapHolder, SerializerEncoding.JSON)); | ||
} | ||
|
||
@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)); | ||
assertEquals("{\"\":\"test\"}", serializer.serialize(map, SerializerEncoding.JSON)); | ||
} | ||
|
||
private static class MapHolder { | ||
@JsonInclude(content = JsonInclude.Include.ALWAYS) | ||
public Map<String,String> map = new HashMap<>(); | ||
} | ||
} | ||
} |
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