Skip to content

Commit 73575b9

Browse files
committed
Add test.
1 parent 1fddd12 commit 73575b9

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/description/type/RecordComponentDescription.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ public TypeDescription.Generic getType() {
890890
*
891891
* @return The token's annotations.
892892
*/
893-
public List<? extends AnnotationDescription> getAnnotations() {
894-
return annotations;
893+
public AnnotationList getAnnotations() {
894+
return new AnnotationList.Explicit(annotations);
895895
}
896896

897897
/**
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package net.bytebuddy.description.type;
2+
3+
import net.bytebuddy.description.annotation.AnnotationDescription;
4+
import net.bytebuddy.test.utility.MockitoRule;
5+
import org.junit.Before;
6+
import org.junit.Rule;
7+
import org.junit.Test;
8+
import org.junit.rules.TestRule;
9+
import org.mockito.Mock;
10+
11+
import java.util.Collections;
12+
13+
import static org.hamcrest.CoreMatchers.is;
14+
import static org.hamcrest.MatcherAssert.assertThat;
15+
import static org.mockito.Mockito.when;
16+
17+
public class RecordComponentDescriptionTokenTest {
18+
19+
private static final String FOO = "foo";
20+
21+
@Rule
22+
public TestRule mockitoRule = new MockitoRule(this);
23+
24+
@Mock
25+
private TypeDescription.Generic type, visitedType;
26+
27+
@Mock
28+
private AnnotationDescription annotation;
29+
30+
@Mock
31+
private TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor;
32+
33+
@Before
34+
@SuppressWarnings("unchecked")
35+
public void setUp() throws Exception {
36+
when(type.asGenericType()).thenReturn(type);
37+
when(visitedType.asGenericType()).thenReturn(visitedType);
38+
when(type.accept((TypeDescription.Generic.Visitor) visitor)).thenReturn(visitedType);
39+
}
40+
41+
@Test
42+
public void testProperties() throws Exception {
43+
RecordComponentDescription.Token token = new RecordComponentDescription.Token(FOO, type, Collections.singletonList(annotation));
44+
assertThat(token.getName(), is(FOO));
45+
assertThat(token.getType(), is(type));
46+
assertThat(token.getAnnotations(), is(Collections.singletonList(annotation)));
47+
}
48+
49+
@Test
50+
public void testVisitor() throws Exception {
51+
assertThat(new RecordComponentDescription.Token(FOO, type, Collections.singletonList(annotation)).accept(visitor),
52+
is(new RecordComponentDescription.Token(FOO, visitedType, Collections.singletonList(annotation))));
53+
}
54+
}

0 commit comments

Comments
 (0)