This repository has been archived by the owner on Nov 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ldreux/master
Support primitive types for annotation builder
- Loading branch information
Showing
2 changed files
with
102 additions
and
22 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
58 changes: 58 additions & 0 deletions
58
src/test/java/io/leangen/geantyref/AnnotationInvocationHandlerTest.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 io.leangen.geantyref; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.unmodifiableMap; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class AnnotationInvocationHandlerTest { | ||
@Test | ||
public void normalize() throws Exception { | ||
// Given | ||
Map<String, Object> values = new HashMap<>(); | ||
values.put("aBoolean", Boolean.FALSE); | ||
values.put("anInt", 42); | ||
|
||
// When | ||
Map<String, Object> normalize = AnnotationInvocationHandler.normalize(MyAnnotation.class, unmodifiableMap(values)); | ||
|
||
// Then | ||
assertThat(normalize, equalTo(values)); | ||
} | ||
|
||
@Test(expected = AnnotationFormatException.class) | ||
public void normalizeWithBadValues() throws Exception { | ||
// Given | ||
Map<String, Object> values = new HashMap<>(); | ||
values.put("aBoolean", "Some text"); | ||
values.put("anInt", 42); | ||
|
||
// When | ||
AnnotationInvocationHandler.normalize(MyAnnotation.class, unmodifiableMap(values)); | ||
} | ||
|
||
@Test | ||
public void normalizeDefaultValues() throws Exception { | ||
// Given | ||
Map<String, Object> values = new HashMap<>(); | ||
values.put("aBoolean", Boolean.FALSE); | ||
values.put("anInt", 0); | ||
|
||
// When | ||
Map<String, Object> normalize = AnnotationInvocationHandler.normalize(MyAnnotation.class, emptyMap()); | ||
|
||
// Then | ||
assertThat(normalize, equalTo(values)); | ||
} | ||
|
||
@interface MyAnnotation { | ||
boolean aBoolean() default false; | ||
|
||
int anInt() default 0; | ||
} | ||
} |