Skip to content

Commit

Permalink
Add tests for method list properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 19, 2020
1 parent 7e0a874 commit 16b5411
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.bytebuddy.description.method;

import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.AbstractFilterableListTest;
import net.bytebuddy.matcher.ElementMatchers;
import org.junit.Test;

import java.util.Collections;
Expand All @@ -13,12 +15,23 @@
public abstract class AbstractMethodListTest<U, V extends MethodDescription> extends AbstractFilterableListTest<V, MethodList<V>, U> {

@Test
@SuppressWarnings("unchecked")
public void testTokenWithMatcher() throws Exception {
assertThat(asList(getFirst()).asTokenList(none()),
is(new ByteCodeElement.Token.TokenList<MethodDescription.Token>(asElement(getFirst()).asToken(none()))));
}

@Test
public void testSignatureToken() throws Exception {
assertThat(asList(getFirst()).asSignatureTokenList(),
is(Collections.singletonList(asElement(getFirst()).asSignatureToken())));
}

@Test
public void testSignatureTokenWithMatcher() throws Exception {
assertThat(asList(getFirst()).asSignatureTokenList(none(), TypeDescription.ForLoadedType.of(Foo.class)),
is(Collections.singletonList(asElement(getFirst()).asToken(none()).asSignatureToken(TypeDescription.ForLoadedType.of(Foo.class)))));
}

@Test
public void testAsDefined() throws Exception {
assertThat(asList(getFirst()).asDefined(), is(Collections.singletonList(asElement(getFirst()).asDefined())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.bytebuddy.description.method;

import net.bytebuddy.description.type.TypeDescription;
import org.junit.Test;

import static net.bytebuddy.matcher.ElementMatchers.none;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

public class MethodListEmptyTest {

Expand All @@ -13,6 +15,16 @@ public void testTokenListWithFilter() throws Exception {
assertThat(new MethodList.Empty<MethodDescription>().asTokenList(none()).size(), is(0));
}

@Test
public void testSignatureTokenList() throws Exception {
assertThat(new MethodList.Empty<MethodDescription>().asSignatureTokenList().size(), is(0));
}

@Test
public void testSignatureTokenListWithFilter() throws Exception {
assertThat(new MethodList.Empty<MethodDescription>().asSignatureTokenList(none(), mock(TypeDescription.class)).size(), is(0));
}

@Test
public void testDeclaredList() throws Exception {
assertThat(new MethodList.Empty<MethodDescription>().asDefined().size(), is(0));
Expand Down

0 comments on commit 16b5411

Please sign in to comment.