-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ClassNameIdResolver doesn't handle resolve Collections$SingletonMap &…
… Collections$SingletonSet (#1823) Fix ClassNameIdResolver - support for Set and Map collections
- Loading branch information
1 parent
fb2d03c
commit 8d6c35d
Showing
2 changed files
with
91 additions
and
10 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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/fasterxml/jackson/databind/jsontype/impl/ClassNameIdResolverTest.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,74 @@ | ||
package com.fasterxml.jackson.databind.jsontype.impl; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(TypeFactory.class) | ||
public class ClassNameIdResolverTest { | ||
|
||
@Mock | ||
private JavaType javaType; | ||
|
||
@Mock | ||
private TypeFactory typeFactory; | ||
|
||
|
||
private ClassNameIdResolver classNameIdResolver; | ||
|
||
@Before | ||
public void setup(){ | ||
this.classNameIdResolver = new ClassNameIdResolver(javaType, typeFactory); | ||
} | ||
|
||
@Test | ||
public void testIdFromValue_shouldUseJavaUtilHashMapForSingletonMap(){ | ||
Map<String, String> singletonMap = Collections.singletonMap("ANY_KEY", "ANY_VALUE"); | ||
|
||
String clazz = classNameIdResolver.idFromValue( singletonMap ); | ||
|
||
assertEquals(clazz, "java.util.HashMap"); | ||
} | ||
|
||
@Test | ||
public void testIdFromValue_shouldUseJavaUtilHashSetForSingletonSet(){ | ||
Set<String> singletonSet = Collections.singleton("ANY_VALUE"); | ||
|
||
String clazz = classNameIdResolver.idFromValue( singletonSet ); | ||
|
||
assertEquals(clazz, "java.util.HashSet"); | ||
} | ||
|
||
@Test | ||
public void testIdFromValue_shouldUseJavaUtilArrayListForSingletonList(){ | ||
List<String> singletonList = Collections.singletonList("ANY_VALUE"); | ||
|
||
String clazz = classNameIdResolver.idFromValue( singletonList ); | ||
|
||
assertEquals(clazz, "java.util.ArrayList"); | ||
} | ||
|
||
@Test | ||
public void testIdFromValue_shouldUseJavaUtilArrayListForArrays$List(){ | ||
List<String> utilList = Arrays.asList("ANY_VALUE"); | ||
|
||
String clazz = classNameIdResolver.idFromValue( utilList ); | ||
|
||
assertEquals(clazz, "java.util.ArrayList"); | ||
} | ||
} |