forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose class information for TypeReference<T> (Azure#24568)
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
sdk/core/azure-core/src/test/java/com/azure/core/util/serializer/TypeReferenceTests.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,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.core.util.serializer; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class TypeReferenceTests { | ||
|
||
@Test | ||
public void createGenericTypeReference() { | ||
final TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() { }; | ||
final Map<String, Object> expectedJavaType = new HashMap<String, Object>() { }; | ||
assertEquals(expectedJavaType.getClass().getGenericSuperclass(), typeReference.getJavaType()); | ||
assertEquals(HashMap.class, typeReference.getJavaClass()); | ||
} | ||
|
||
@Test | ||
public void createFactoryInstance() { | ||
TypeReference<Integer> typeReference = TypeReference.createInstance(int.class); | ||
assertEquals(int.class, typeReference.getJavaType()); | ||
assertEquals(int.class, typeReference.getJavaClass()); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Test | ||
public void createTypeReferenceWithoutType() { | ||
IllegalArgumentException thrown | ||
= assertThrows(IllegalArgumentException.class, () -> new TypeReference() { }); | ||
assertEquals("Type constructed without type information.", thrown.getMessage()); | ||
} | ||
} |