From 73575b9350063b07e6dcf9be4a7c2a710edbf9f1 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 29 Apr 2020 19:28:47 +0200 Subject: [PATCH] Add test. --- .../type/RecordComponentDescription.java | 4 +- .../RecordComponentDescriptionTokenTest.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 byte-buddy-dep/src/test/java/net/bytebuddy/description/type/RecordComponentDescriptionTokenTest.java diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/RecordComponentDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/RecordComponentDescription.java index e702707d938..a8f227f61a1 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/RecordComponentDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/RecordComponentDescription.java @@ -890,8 +890,8 @@ public TypeDescription.Generic getType() { * * @return The token's annotations. */ - public List getAnnotations() { - return annotations; + public AnnotationList getAnnotations() { + return new AnnotationList.Explicit(annotations); } /** diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/RecordComponentDescriptionTokenTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/RecordComponentDescriptionTokenTest.java new file mode 100644 index 00000000000..7f0922ba6a2 --- /dev/null +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/RecordComponentDescriptionTokenTest.java @@ -0,0 +1,54 @@ +package net.bytebuddy.description.type; + +import net.bytebuddy.description.annotation.AnnotationDescription; +import net.bytebuddy.test.utility.MockitoRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.mockito.Mock; + +import java.util.Collections; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +public class RecordComponentDescriptionTokenTest { + + private static final String FOO = "foo"; + + @Rule + public TestRule mockitoRule = new MockitoRule(this); + + @Mock + private TypeDescription.Generic type, visitedType; + + @Mock + private AnnotationDescription annotation; + + @Mock + private TypeDescription.Generic.Visitor visitor; + + @Before + @SuppressWarnings("unchecked") + public void setUp() throws Exception { + when(type.asGenericType()).thenReturn(type); + when(visitedType.asGenericType()).thenReturn(visitedType); + when(type.accept((TypeDescription.Generic.Visitor) visitor)).thenReturn(visitedType); + } + + @Test + public void testProperties() throws Exception { + RecordComponentDescription.Token token = new RecordComponentDescription.Token(FOO, type, Collections.singletonList(annotation)); + assertThat(token.getName(), is(FOO)); + assertThat(token.getType(), is(type)); + assertThat(token.getAnnotations(), is(Collections.singletonList(annotation))); + } + + @Test + public void testVisitor() throws Exception { + assertThat(new RecordComponentDescription.Token(FOO, type, Collections.singletonList(annotation)).accept(visitor), + is(new RecordComponentDescription.Token(FOO, visitedType, Collections.singletonList(annotation)))); + } +}