Skip to content

Commit

Permalink
chore(test): Dependency Update (#240)
Browse files Browse the repository at this point in the history
* chore(test): bump mockito test dependency to 4.4.0
* chore(test): migrate junit test dependency to 5.8.2
  • Loading branch information
CarstenWickner committed Apr 3, 2022
1 parent 0775b4b commit 3ab1374
Show file tree
Hide file tree
Showing 43 changed files with 1,628 additions and 1,694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,56 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test for the {@link FieldScope} class.
*/
@RunWith(JUnitParamsRunner.class)
public class FieldScopeTest extends AbstractTypeAwareTest {

public FieldScopeTest() {
super(TestClass.class);
}

@Before
@BeforeEach
public void setUp() {
this.prepareContextForVersion(SchemaVersion.DRAFT_2019_09);
}

Object parametersForTestFindGetter() {
return new String[][]{
{"fieldWithoutGetter", null, null},
{"fieldWithoutGetter", "fieldWithPublicGetter", null},
{"fieldWithPrivateGetter", null, null},
{"fieldWithPublicGetter", null, "getFieldWithPublicGetter"},
{"fieldWithPublicGetter", "fieldWithoutGetter", "getFieldWithPublicGetter"},
{"fieldWithPublicBooleanGetter", null, "isFieldWithPublicBooleanGetter"}};
static Stream<Arguments> parametersForTestFindGetter() {
return Stream.of(
Arguments.of("fieldWithoutGetter", null, null),
Arguments.of("fieldWithoutGetter", "fieldWithPublicGetter", null),
Arguments.of("fieldWithPrivateGetter", null, null),
Arguments.of("fieldWithPublicGetter", null, "getFieldWithPublicGetter"),
Arguments.of("fieldWithPublicGetter", "fieldWithoutGetter", "getFieldWithPublicGetter"),
Arguments.of("fieldWithPublicBooleanGetter", null, "isFieldWithPublicBooleanGetter")
);
}

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForTestFindGetter")
public void testFindGetter(String fieldName, String fieldNameOverride, String methodName) throws Exception {
FieldScope field = this.getTestClassField(fieldName)
.withOverriddenName(fieldNameOverride);
MethodScope getter = field.findGetter();

if (methodName == null) {
Assert.assertNull(getter);
Assertions.assertNull(getter);
} else {
Assert.assertNotNull(getter);
Assert.assertEquals(methodName, getter.getName());
Assertions.assertNotNull(getter);
Assertions.assertEquals(methodName, getter.getName());
}
}

@Test
@Parameters({
@ParameterizedTest
@CsvSource({
"fieldWithoutGetter, false",
"fieldWithPrivateGetter, false",
"fieldWithPublicGetter, true",
Expand All @@ -78,11 +79,11 @@ public void testHasGetter(String fieldName, boolean expectedResult) throws Excep
FieldScope field = this.getTestClassField(fieldName);
boolean result = field.hasGetter();

Assert.assertEquals(expectedResult, result);
Assertions.assertEquals(expectedResult, result);
}

@Test
@Parameters({
@ParameterizedTest
@CsvSource({
"fieldWithoutGetter, false",
"fieldWithPrivateGetter, true",
"fieldWithPublicGetter, false",
Expand All @@ -93,9 +94,9 @@ public void testGetAnnotationConsideringFieldAndGetter(String fieldName, boolean
TestAnnotation annotation = field.getAnnotationConsideringFieldAndGetter(TestAnnotation.class);

if (annotationExpectedToBeFound) {
Assert.assertNotNull(annotation);
Assertions.assertNotNull(annotation);
} else {
Assert.assertNull(annotation);
Assertions.assertNull(annotation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test for the {@link MemberScope} class.
*/
@RunWith(JUnitParamsRunner.class)
public class MemberScopeTest extends AbstractTypeAwareTest {

public MemberScopeTest() {
super(TestClass.class);
}

@Before
@BeforeEach
public void setUp() {
this.prepareContextForVersion(SchemaVersion.DRAFT_2019_09);
}

@Test
@Parameters({
@ParameterizedTest
@CsvSource({
"privateVisibleField, true, false, false",
"packageVisibleField, false, false, false",
"protectedVisibleField, false, true, false",
Expand All @@ -53,54 +53,56 @@ public void setUp() {
public void testGetVisibility(String fieldName, boolean isPrivate, boolean isProtected, boolean isPublic) {
FieldScope field = this.getTestClassField(fieldName);

Assert.assertEquals(isPrivate, field.isPrivate());
Assert.assertEquals(isProtected, field.isProtected());
Assert.assertEquals(isPublic, field.isPublic());
Assertions.assertEquals(isPrivate, field.isPrivate());
Assertions.assertEquals(isProtected, field.isProtected());
Assertions.assertEquals(isPublic, field.isPublic());
}

Object parametersForTestContainerType() {
return new Object[][]{
{"getStringArray", true, String.class},
{"getRawCollection", true, Object.class},
{"getListOfIntArrays", true, int[].class},
{"getMapWithNestedGenerics", false, null},
{"getBooleanField", false, null},
{"executeVoidMethod", false, null}};
static Stream<Arguments> parametersForTestContainerType() {
return Stream.of(
Arguments.of("getStringArray", true, String.class),
Arguments.of("getRawCollection", true, Object.class),
Arguments.of("getListOfIntArrays", true, int[].class),
Arguments.of("getMapWithNestedGenerics", false, null),
Arguments.of("getBooleanField", false, null),
Arguments.of("executeVoidMethod", false, null)
);
}

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForTestContainerType")
public void testContainerType(String methodName, boolean isContainerType, Class<?> expectedItemType) throws Exception {
MethodScope method = this.getTestClassMethod(methodName);

Assert.assertEquals(isContainerType, method.isContainerType());
Assertions.assertEquals(isContainerType, method.isContainerType());
ResolvedType itemType = method.getContainerItemType();
if (expectedItemType == null) {
Assert.assertNull(itemType);
Assertions.assertNull(itemType);
} else {
Assert.assertNotNull(itemType);
Assert.assertSame(expectedItemType, itemType.getErasedType());
Assertions.assertNotNull(itemType);
Assertions.assertSame(expectedItemType, itemType.getErasedType());
}
}

Object parametersForTestTypeDescription() {
return new Object[][]{
{"getStringArray", "String[]", "java.lang.String[]"},
{"getRawCollection", "Collection", "java.util.Collection"},
{"getListOfIntArrays", "List<int[]>", "java.util.List<int[]>"},
{"getMapWithNestedGenerics", "Map<String, Map<String, List<Set<Class<Object>>>>>",
"java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.util.List<java.util.Set<java.lang.Class<java.lang.Object>>>>>"},
{"getBooleanField", "Boolean", "java.lang.Boolean"},
{"executeVoidMethod", "void", "void"}};
static Stream<Arguments> parametersForTestTypeDescription() {
return Stream.of(
Arguments.of("getStringArray", "String[]", "java.lang.String[]"),
Arguments.of("getRawCollection", "Collection", "java.util.Collection"),
Arguments.of("getListOfIntArrays", "List<int[]>", "java.util.List<int[]>"),
Arguments.of("getMapWithNestedGenerics", "Map<String, Map<String, List<Set<Class<Object>>>>>",
"java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.util.List<java.util.Set<java.lang.Class<java.lang.Object>>>>>"),
Arguments.of("getBooleanField", "Boolean", "java.lang.Boolean"),
Arguments.of("executeVoidMethod", "void", "void")
);
}

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForTestTypeDescription")
public void testTypeDescription(String methodName, String simpleTypeDescription, String fullTypeDescription) throws Exception {
MethodScope method = this.getTestClassMethod(methodName);

Assert.assertEquals(simpleTypeDescription, method.getSimpleTypeDescription());
Assert.assertEquals(fullTypeDescription, method.getFullTypeDescription());
Assertions.assertEquals(simpleTypeDescription, method.getSimpleTypeDescription());
Assertions.assertEquals(fullTypeDescription, method.getFullTypeDescription());
}

private static class TestClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,62 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Test for the {@link MethodSCope} class.
*/
@RunWith(JUnitParamsRunner.class)
public class MethodScopeTest extends AbstractTypeAwareTest {

public MethodScopeTest() {
super(TestClass.class);
}

@Before
@BeforeEach
public void setUp() {
this.prepareContextForVersion(SchemaVersion.DRAFT_2019_09);
}

Object parametersForTestFindGetterField() {
return new String[][]{
{"getFieldWithPrivateGetter", null, null},
{"getFieldWithPrivateGetter", "getFieldWithPublicGetter", null},
{"getFieldWithPublicGetter", null, "fieldWithPublicGetter"},
{"getFieldWithPublicGetter", "getFieldWithPrivateGetter", "fieldWithPublicGetter"},
{"isFieldWithPublicBooleanGetter", null, "fieldWithPublicBooleanGetter"},
{"isFieldWithPublicBooleanGetter", "isBehavingSomehow", "fieldWithPublicBooleanGetter"},
{"getCalculatedValue", null, null},
{"isBehavingSomehow", null, null},
{"isBehavingSomehow", "isFieldWithPublicBooleanGetter", null},
{"get", null, null},
{"is", null, null},
{"calculateSomething", null, null}};
static Stream<Arguments> parametersForTestFindGetterField() {
return Stream.of(
Arguments.of("getFieldWithPrivateGetter", null, null),
Arguments.of("getFieldWithPrivateGetter", "getFieldWithPublicGetter", null),
Arguments.of("getFieldWithPublicGetter", null, "fieldWithPublicGetter"),
Arguments.of("getFieldWithPublicGetter", "getFieldWithPrivateGetter", "fieldWithPublicGetter"),
Arguments.of("isFieldWithPublicBooleanGetter", null, "fieldWithPublicBooleanGetter"),
Arguments.of("isFieldWithPublicBooleanGetter", "isBehavingSomehow", "fieldWithPublicBooleanGetter"),
Arguments.of("getCalculatedValue", null, null),
Arguments.of("isBehavingSomehow", null, null),
Arguments.of("isBehavingSomehow", "isFieldWithPublicBooleanGetter", null),
Arguments.of("get", null, null),
Arguments.of("is", null, null),
Arguments.of("calculateSomething", null, null)
);
}

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForTestFindGetterField")
public void testFindGetterField(String methodName, String methodNameOverride, String fieldName) throws Exception {
MethodScope method = this.getTestClassMethod(methodName)
.withOverriddenName(methodNameOverride);
FieldScope field = method.findGetterField();

if (fieldName == null) {
Assert.assertNull(field);
Assertions.assertNull(field);
} else {
Assert.assertNotNull(field);
Assert.assertEquals(fieldName, field.getDeclaredName());
Assertions.assertNotNull(field);
Assertions.assertEquals(fieldName, field.getDeclaredName());
}
}

@Test
@Parameters({
@ParameterizedTest
@CsvSource({
"getFieldWithPrivateGetter, false",
"getFieldWithPublicGetter, true",
"isFieldWithPublicBooleanGetter, true",
Expand All @@ -88,11 +89,11 @@ public void testIsGetter(String methodName, boolean expectedResult) throws Excep
MethodScope method = this.getTestClassMethod(methodName);
boolean result = method.isGetter();

Assert.assertEquals(expectedResult, result);
Assertions.assertEquals(expectedResult, result);
}

@Test
@Parameters({
@ParameterizedTest
@CsvSource({
"calculateSomething, false",
"getFieldWithPrivateGetter, true",
"getFieldWithPublicGetter, false",
Expand All @@ -103,9 +104,9 @@ public void testGetAnnotationConsideringFieldAndGetter(String methodName, boolea
TestAnnotation annotation = method.getAnnotationConsideringFieldAndGetter(TestAnnotation.class);

if (annotationExpectedToBeFound) {
Assert.assertNotNull(annotation);
Assertions.assertNotNull(annotation);
} else {
Assert.assertNull(annotation);
Assertions.assertNull(annotation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.victools.jsonschema.generator.impl.TypeContextFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;

Expand All @@ -31,7 +31,7 @@ public class SchemaBuilderTest {
private SchemaGeneratorConfig config;
private TypeContext typeContext;

@Before
@BeforeEach
public void setUp() {
this.config = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON)
.with(Option.PLAIN_DEFINITION_KEYS)
Expand Down

0 comments on commit 3ab1374

Please sign in to comment.