Skip to content

Migrate to JUnit 5 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# GeantyRef

## Migrate to JUnit 5 with Symflower

* Symflower version: 44511
* Execution time: 1.9s
* Diff: 11 files changed, 56 insertions(+), 44 deletions(-)

[![Maven Central](https://img.shields.io/maven-central/v/io.leangen.geantyref/geantyref?color=green&style=flat-square)](https://maven-badges.herokuapp.com/maven-central/io.leangen.geantyref/geantyref)
[![Javadoc](https://img.shields.io/badge/dynamic/json.svg?style=flat-square&prefix=v&color=green&label=javadoc&query=$.response.docs[0].latestVersion&uri=http%3A%2F%2Fsearch.maven.org%2Fsolrsearch%2Fselect%3Fq%3Dg%3A%2522io.leangen.geantyref%2522%2BAND%2Ba%3A%2522geantyref%2522%26wt%3Djson)](http://www.javadoc.io/doc/io.leangen.geantyref/geantyref)
[![Build Status](https://img.shields.io/travis/leangen/geantyref?style=flat-square)](https://travis-ci.org/leangen/geantyref)
Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.11.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;
import java.util.RandomAccess;

import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

//NOTE: It is important NOT to use <> (diamond) here! Something goes horribly wrong with type inference.
@SuppressWarnings("Convert2Diamond")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.leangen.geantyref;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -9,6 +9,7 @@
import static java.util.Collections.unmodifiableMap;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AnnotationInvocationHandlerTest {
@Test
Expand All @@ -25,15 +26,17 @@ public void normalize() throws Exception {
assertThat(normalize, equalTo(values));
}

@Test(expected = AnnotationFormatException.class)
@Test
public void normalizeWithBadValues() throws Exception {
// Given
Map<String, Object> values = new HashMap<>();
values.put("aBoolean", "Some text");
values.put("anInt", 42);

// When
AnnotationInvocationHandler.normalize(MyAnnotation.class, unmodifiableMap(values));
assertThrows(AnnotationFormatException.class, () -> {
// Given
Map<String, Object> values = new HashMap<>();
values.put("aBoolean", "Some text");
values.put("anInt", 42);

// When
AnnotationInvocationHandler.normalize(MyAnnotation.class, unmodifiableMap(values));
});
}

@Test
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/io/leangen/geantyref/AnnotationsMergeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.leangen.geantyref;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedArrayType;
Expand All @@ -23,10 +23,10 @@
import static io.leangen.geantyref.Annotations.A3;
import static io.leangen.geantyref.Annotations.A4;
import static io.leangen.geantyref.Annotations.A5;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests if type-use annotations from different locations are inherited and merged correctly.
Expand Down Expand Up @@ -105,7 +105,7 @@ public void classAnnotationsMergeTest() throws NoSuchFieldException {
public void classAnnotationsNonPropagationTest() {
AnnotatedType number = GenericTypeReflector.getExactSuperType(A1_LONG, Number.class);
assertNotNull(number);
assertTrue("Class annotations are not propagated upwards", number.getAnnotations().length == 0);
assertTrue(number.getAnnotations().length == 0, "Class annotations are not propagated upwards");
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/leangen/geantyref/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class Assertions {

Expand All @@ -33,7 +33,7 @@ public static void assertTypeIsRecursive(AnnotatedParameterizedType type) {
.filter(arg -> arg instanceof AnnotatedTypeVariable)
.map(arg -> (AnnotatedTypeVariable) arg)
.collect(Collectors.toCollection(() -> Collections.newSetFromMap(new IdentityHashMap<>())));
assertTrue("Variable " + type + " does not recur within given depth", isRecursive(roots, type, 0, 10));
assertTrue(isRecursive(roots, type, 0, 10), "Variable " + type + " does not recur within given depth");
}

private static boolean isRecursive(Set<AnnotatedTypeVariable> roots, AnnotatedType node, int currentDepth, int maxDepth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

class GenTyRefReflectionStrategy extends AbstractReflectionStrategy {
public boolean isSupertype(Type superType, Type subType) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/leangen/geantyref/Issue17Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

package io.leangen.geantyref;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/*
* https://github.com/leangen/geantyref/issues/17
Expand All @@ -23,9 +23,9 @@ public void testTypeTokenEqualityAndHashCode() throws NoSuchMethodException {
Method method = Issue17Test.class.getDeclaredMethod("dummyMethod", Set.class);
TypeToken<?> otherTypeToken = TypeToken.get(method.getParameters()[0].getParameterizedType());

assertEquals("Both TypeTokens should be equal", numberTypeToken, otherTypeToken);
assertEquals("Both TypeTokens should have equal types", numberTypeToken.getType(), otherTypeToken.getType());
assertEquals("Both TypeTokens should have equal hash codes", numberTypeToken.hashCode(), otherTypeToken.hashCode());
assertEquals(numberTypeToken, otherTypeToken, "Both TypeTokens should be equal");
assertEquals(numberTypeToken.getType(), otherTypeToken.getType(), "Both TypeTokens should have equal types");
assertEquals(numberTypeToken.hashCode(), otherTypeToken.hashCode(), "Both TypeTokens should have equal hash codes");
}

@SuppressWarnings("unused")
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/leangen/geantyref/Issue20Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.leangen.geantyref;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedParameterizedType;
Expand All @@ -14,10 +14,10 @@
import java.util.Arrays;

import static io.leangen.geantyref.Annotations.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* <a href="https://github.com/leangen/geantyref/issues/20">reduceBounded StackOverflowError with self-recursing capture</a>
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/io/leangen/geantyref/Issue27Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.leangen.geantyref;

import io.leangen.geantyref.Annotations.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.lang.reflect.*;
import java.util.Map;
Expand All @@ -15,6 +15,7 @@
import static io.leangen.geantyref.Assertions.assertAnnotationsPresent;
import static io.leangen.geantyref.Assertions.assertEqualTypeVariables;
import static io.leangen.geantyref.Assertions.assertTypeIsRecursive;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* <a href="https://github.com/leangen/geantyref/issues/27">StackOverflowError in VarMap.map when calling GenericTypeReflector.getParameterTypes()</a>
Expand Down Expand Up @@ -46,11 +47,13 @@ public void getParameterTypesOnRecursiveType() throws NoSuchMethodException {
}
}

@Test(expected = UnresolvedTypeVariableException.class)
@Test
public void getExactParameterTypesOnRecursiveType() throws NoSuchMethodException {
Class<?> cls = SelfReferential.class;
Method method = reflectSelfRefMethod(cls);
GenericTypeReflector.getExactParameterTypes(method, cls);
assertThrows(UnresolvedTypeVariableException.class, () -> {
Class<?> cls = SelfReferential.class;
Method method = reflectSelfRefMethod(cls);
GenericTypeReflector.getExactParameterTypes(method, cls);
});
}

private static Method reflectSelfRefMethod(Class<?> cls) throws NoSuchMethodException {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/leangen/geantyref/ToStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import io.leangen.geantyref.Annotations.A3;
import io.leangen.geantyref.Annotations.A4;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.Serializable;
import java.lang.annotation.Annotation;
Expand All @@ -17,8 +17,8 @@
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ToStringTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.*;

import static io.leangen.geantyref.TypeFactory.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class TypeFactoryTest extends TestCase {
private static final Type GENERICOUTER_STRING = new TypeToken<GenericOuter<String>>() {
Expand Down