Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 29, 2020
1 parent 1fddd12 commit 73575b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,8 @@ public TypeDescription.Generic getType() {
*
* @return The token's annotations.
*/
public List<? extends AnnotationDescription> getAnnotations() {
return annotations;
public AnnotationList getAnnotations() {
return new AnnotationList.Explicit(annotations);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends TypeDescription.Generic> 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))));
}
}

0 comments on commit 73575b9

Please sign in to comment.