|
| 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