Skip to content

Commit

Permalink
Refactored annotation-visibility testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Dec 21, 2015
1 parent 5d33f55 commit 44b8b2f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 58 deletions.
Expand Up @@ -28,9 +28,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.*;

public abstract class AbstractAnnotationBinderTest<T extends Annotation> {

private final Class<T> annotationType;
public abstract class AbstractAnnotationBinderTest<T extends Annotation> extends AbstractAnnotationTest<T> {

@Rule
public TestRule mockitoRule = new MockitoRule(this);
Expand Down Expand Up @@ -67,7 +65,7 @@ public abstract class AbstractAnnotationBinderTest<T extends Annotation> {
protected TypeList rawSourceTypeList;

protected AbstractAnnotationBinderTest(Class<T> annotationType) {
this.annotationType = annotationType;
super(annotationType);
}

protected abstract TargetMethodAnnotationDrivenBinder.ParameterBinder<T> getSimpleBinder();
Expand Down
@@ -0,0 +1,25 @@
package net.bytebuddy.implementation.bind.annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public abstract class AbstractAnnotationTest<T extends Annotation> {

protected final Class<T> annotationType;

protected AbstractAnnotationTest(Class<T> annotationType) {
this.annotationType = annotationType;
}

@Test
public void testAnnotationVisibility() throws Exception {
assertThat(annotationType.isAnnotationPresent(Retention.class), is(true));
assertThat(annotationType.getAnnotation(Retention.class).value(), is(RetentionPolicy.RUNTIME));
}
}

This file was deleted.

Expand Up @@ -16,7 +16,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

public class BindingPriorityResolverTest {
public class BindingPriorityResolverTest extends AbstractAnnotationTest<BindingPriority> {

@Rule
public TestRule mockitoRule = new MockitoRule(this);
Expand All @@ -33,6 +33,10 @@ public class BindingPriorityResolverTest {
@Mock
private BindingPriority highPriority, lowPriority;

public BindingPriorityResolverTest() {
super(BindingPriority.class);
}

@Before
public void setUp() throws Exception {
when(left.getTarget()).thenReturn(leftMethod);
Expand Down
Expand Up @@ -18,7 +18,7 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

public class IgnoreForBindingVerifierTest {
public class IgnoreForBindingVerifierTest extends AbstractAnnotationTest<IgnoreForBinding> {

@Rule
public TestRule mockitoRule = new MockitoRule(this);
Expand All @@ -29,6 +29,10 @@ public class IgnoreForBindingVerifierTest {
@Mock
private AnnotationList annotationList;

public IgnoreForBindingVerifierTest() {
super(IgnoreForBinding.class);
}

@Before
public void setUp() throws Exception {
when(methodDescription.getDeclaredAnnotations()).thenReturn(annotationList);
Expand Down
Expand Up @@ -19,7 +19,7 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

public class RuntimeTypeVerifierTest {
public class RuntimeTypeVerifierTest extends AbstractAnnotationTest<RuntimeType> {

@Rule
public TestRule mockitoRule = new MockitoRule(this);
Expand All @@ -30,6 +30,10 @@ public class RuntimeTypeVerifierTest {
@Mock
private RuntimeType runtimeType;

public RuntimeTypeVerifierTest() {
super(RuntimeType.class);
}

@Before
public void setUp() throws Exception {
doReturn(RuntimeType.class).when(runtimeType).annotationType();
Expand Down

0 comments on commit 44b8b2f

Please sign in to comment.