Skip to content

Commit

Permalink
Merge branch 'tweak.java.compiler.options'
Browse files Browse the repository at this point in the history
* tweak.java.compiler.options:
  replace Java 9 deprecated newInstance() with constructor.newInstance()
  replace MockitoJUnitRunner with non-deprecated version
  tweak Java compiler options and remove or suppress warnings
  • Loading branch information
aaschmid committed Jul 10, 2018
2 parents 243ce7f + f35c736 commit ce7ebd8
Show file tree
Hide file tree
Showing 24 changed files with 119 additions and 91 deletions.
27 changes: 20 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.2"
classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.2'
}
}

Expand Down Expand Up @@ -52,6 +52,11 @@ subprojects {
group = 'com.tngtech.junit.dataprovider'
version = '2.3'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs += [ '-Xlint:all', '-Werror' ]
}

tasks.withType(Jar) {
from(project.rootDir) {
include 'LICENSE.md', 'LICENSE-notice.md'
Expand All @@ -77,6 +82,10 @@ project(':core') {
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.18.3'
}

tasks.withType(JavaCompile) {
options.compilerArgs += [ '-Xlint:-options' ]
}

jar {
manifest {
attributes(
Expand Down Expand Up @@ -119,6 +128,10 @@ project(':junit4') {
integTestCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.7'
}

tasks.withType(JavaCompile) {
options.compilerArgs += [ '-Xlint:-options' ]
}

jar {
manifest {
attributes(
Expand Down Expand Up @@ -168,6 +181,10 @@ configure(subprojects.findAll{ p -> p.name.startsWith('junit-jupiter') }) {
integTestCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.12'
}

tasks.withType(JavaCompile) {
options.compilerArgs += [ '-parameters' ]
}

test {
useJUnitPlatform()
}
Expand Down Expand Up @@ -219,10 +236,6 @@ project(':junit-jupiter-params') {

// configure after properties are set and integration tests are added
subprojects {
tasks.withType(JavaCompile) {
options.compilerArgs += [ "-parameters" ]
}

jar {
manifest {
def now = new Date()
Expand Down Expand Up @@ -306,7 +319,7 @@ subprojects {
}

cpd {
if (System.getProperty("java.version")[0..2] in [ '1.6' ]) { // PMD / CPD v5.4.0 does not work with Java < v1.7 :-(
if (System.getProperty('java.version')[0..2] in [ '1.6' ]) { // PMD / CPD v5.4.0 does not work with Java < v1.7 :-(
toolVersion = '5.3.7'
} else {
toolVersion = '6.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void testConvertShouldThrowExceptionIfVarargsAndNumberOfArgumentsIsTwoLes
public void testConvertShouldCorrectlyParseAllPrimitiveTypes() {
// Given:
String data = "true,1,c,2,3,4,5.5,6.6";
Class<?>[] parameterTypes = new Class[] { boolean.class, byte.class, char.class, short.class, int.class,
Class<?>[] parameterTypes = new Class<?>[] { boolean.class, byte.class, char.class, short.class, int.class,
long.class, float.class, double.class };

when(context.getSplitBy()).thenReturn(",");
Expand All @@ -119,7 +119,7 @@ public void testConvertShouldCorrectlyParseAllPrimitiveTypes() {
public void testConvertShouldCorrectlyParseAllPrimitiveTypesAsJavaString() {
// Given:
String data = "-5;2014l;-1.234567f;-901e-3";
Class<?>[] parameterTypes = new Class[] { int.class, long.class, float.class, double.class };
Class<?>[] parameterTypes = new Class<?>[] { int.class, long.class, float.class, double.class };

when(context.getSplitBy()).thenReturn(";");

Expand All @@ -134,7 +134,7 @@ public void testConvertShouldCorrectlyParseAllPrimitiveTypesAsJavaString() {
public void testConvertShouldNotTrimValuesIfSettingsTrimIsFalse() {
// Given:
String data = " foo| bar |baz ";
Class<?>[] parameterTypes = new Class[] { String.class, String.class, String.class };
Class<?>[] parameterTypes = new Class<?>[] { String.class, String.class, String.class };

when(context.getSplitBy()).thenReturn("\\|");

Expand All @@ -149,7 +149,7 @@ public void testConvertShouldNotTrimValuesIfSettingsTrimIsFalse() {
public void testConvertShouldTrimAndParseAllPrimitiveTypesIfSettingsTrimIsTrue() {
// Given:
String data = " false ; 11 ; z ; 22 ; 33 ;44 ; 55.55 ; 66.66 ";
Class<?>[] parameterTypes = new Class[] { boolean.class, byte.class, char.class, short.class, int.class,
Class<?>[] parameterTypes = new Class<?>[] { boolean.class, byte.class, char.class, short.class, int.class,
long.class, float.class, double.class };

when(context.getSplitBy()).thenReturn(";");
Expand All @@ -166,7 +166,7 @@ public void testConvertShouldTrimAndParseAllPrimitiveTypesIfSettingsTrimIsTrue()
public void testConvertShouldTrimNonSpaceWhitespaceCharsIfSettingsTrimIsTrue() {
// Given:
String data = "\n-1f\n,\r-2\r,\t3.0d\t";
Class<?>[] parameterTypes = new Class[] { float.class, int.class, double.class };
Class<?>[] parameterTypes = new Class<?>[] { float.class, int.class, double.class };

when(context.getSplitBy()).thenReturn(",");
when(context.isTrimValues()).thenReturn(true);
Expand All @@ -182,7 +182,7 @@ public void testConvertShouldTrimNonSpaceWhitespaceCharsIfSettingsTrimIsTrue() {
public void testConvertShouldNotTrimNonBreakingSpaceEvenIfSettingsTrimIsTrue() {
// Given:
String data = "\u00A0test\u00A0";
Class<?>[] parameterTypes = new Class[] { String.class };
Class<?>[] parameterTypes = new Class<?>[] { String.class };

when(context.isTrimValues()).thenReturn(true);

Expand All @@ -197,7 +197,7 @@ public void testConvertShouldNotTrimNonBreakingSpaceEvenIfSettingsTrimIsTrue() {
public void testConvertShouldCorrectlyHandleLeadingEmptyString() {
// Given:
String data = "/true";
Class<?>[] parameterTypes = new Class[] { String.class, boolean.class };
Class<?>[] parameterTypes = new Class<?>[] { String.class, boolean.class };

when(context.getSplitBy()).thenReturn("/");
when(context.isTrimValues()).thenReturn(true);
Expand All @@ -213,7 +213,7 @@ public void testConvertShouldCorrectlyHandleLeadingEmptyString() {
public void testConvertShouldCorrectlyHandleTrailingEmptyString() {
// Given:
String data = "1 ";
Class<?>[] parameterTypes = new Class[] { int.class, String.class };
Class<?>[] parameterTypes = new Class<?>[] { int.class, String.class };

when(context.getSplitBy()).thenReturn(" ");
when(context.isTrimValues()).thenReturn(true);
Expand All @@ -229,7 +229,7 @@ public void testConvertShouldCorrectlyHandleTrailingEmptyString() {
public void testConvertShouldThrowIllegalArgumentExceptionIfCharHasNotLengthOne() {
// Given:
String data = "noChar";
Class<?>[] parameterTypes = new Class[] { char.class };
Class<?>[] parameterTypes = new Class<?>[] { char.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("'noChar' cannot be converted to type 'char'");
Expand All @@ -244,7 +244,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionIfCharHasNotLengthOne(
public void testConvertShouldThrowIllegalArgumentExceptionIfValueOfThrowsNumberFormatException() {
// Given:
String data = "noInt";
Class<?>[] parameterTypes = new Class[] { int.class };
Class<?>[] parameterTypes = new Class<?>[] { int.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot convert 'noInt' to type 'int'");
Expand All @@ -259,7 +259,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionIfValueOfThrowsNumberF
public void testConvertShouldThrowIllegalArgumentExceptionForTargetTypeConstructorWithStringArgWhichThrowsException() {
// Given:
String data = "noInt";
Class<?>[] parameterTypes = new Class[] { BigInteger.class };
Class<?>[] parameterTypes = new Class<?>[] { BigInteger.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
Expand All @@ -275,7 +275,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionForTargetTypeConstruct
public void testConvertShouldThrowIllegalArgumentExceptionForUnsupportedTargetType() {
// Given:
String data = "noObject";
Class<?>[] parameterTypes = new Class[] { Object.class };
Class<?>[] parameterTypes = new Class<?>[] { Object.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
Expand All @@ -291,7 +291,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionForUnsupportedTargetTy
public void testConvertShouldCorrectlyParseEnum() {
// Given:
String data = " VAL1, VAL2 ";
Class<?>[] parameterTypes = new Class[] { TestEnum.class, TestEnum.class };
Class<?>[] parameterTypes = new Class<?>[] { TestEnum.class, TestEnum.class };

when(context.getSplitBy()).thenReturn(",");
when(context.isTrimValues()).thenReturn(true);
Expand All @@ -307,7 +307,7 @@ public void testConvertShouldCorrectlyParseEnum() {
public void testConvertShouldThrowIllegalArgumentExceptionIfEnumValuesIsInvalid() {
// Given:
String data = "Val1";
Class<?>[] parameterTypes = new Class[] { TestEnum.class };
Class<?>[] parameterTypes = new Class<?>[] { TestEnum.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
Expand All @@ -323,7 +323,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionIfEnumValuesIsInvalid(
public void testConvertShouldCorrectlyParseEnumIgnoringCase() {
// Given:
String data = "Val1,val2";
Class<?>[] parameterTypes = new Class[] { TestEnum.class, TestEnum.class };
Class<?>[] parameterTypes = new Class<?>[] { TestEnum.class, TestEnum.class };

when(context.getSplitBy()).thenReturn(",");
when(context.isIgnoreEnumCase()).thenReturn(true);
Expand All @@ -339,7 +339,7 @@ public void testConvertShouldCorrectlyParseEnumIgnoringCase() {
public void testConvertShouldThrowIllegalArgumentExceptionIfEnumValueIsInvalid() {
// Given:
String data = "UNKNOW_ENUM_VALUE";
Class<?>[] parameterTypes = new Class[] { TestEnum.class };
Class<?>[] parameterTypes = new Class<?>[] { TestEnum.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage(
Expand All @@ -355,7 +355,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionIfEnumValueIsInvalid()
public void testConvertShouldCorrectlyParseClass() {
// Given:
String data = " java.lang.Thread, com.tngtech.junit.dataprovider.DataProviders ";
Class<?>[] parameterTypes = new Class[] { Class.class, Class.class };
Class<?>[] parameterTypes = new Class<?>[] { Class.class, Class.class };

when(context.getSplitBy()).thenReturn(",");
when(context.isTrimValues()).thenReturn(true);
Expand All @@ -371,7 +371,7 @@ public void testConvertShouldCorrectlyParseClass() {
public void testConvertShouldThrowIllegalArgumentExceptionIfClassNameIsInvalid() {
// Given:
String data = "String";
Class<?>[] parameterTypes = new Class[] { Class.class };
Class<?>[] parameterTypes = new Class<?>[] { Class.class };

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Unable to instantiate 'Class' for 'String'");
Expand All @@ -386,7 +386,7 @@ public void testConvertShouldThrowIllegalArgumentExceptionIfClassNameIsInvalid()
public void testConvertShouldCorrectlyParseAllPrimitiveWrapperTypes() {
// Given:
String data = "true,1,c,2,3,4,5.5,6.6";
Class<?>[] parameterTypes = new Class[] { Boolean.class, Byte.class, Character.class, Short.class,
Class<?>[] parameterTypes = new Class<?>[] { Boolean.class, Byte.class, Character.class, Short.class,
Integer.class, Long.class, Float.class, Double.class };

when(context.getSplitBy()).thenReturn(",");
Expand All @@ -404,7 +404,7 @@ public void testConvertShouldCorrectlyParseAllPrimitiveWrapperTypes() {
public void testConvertShouldParseNullValuesAsStringIfSettingsConvertNullsIsFalse() {
// Given:
String data = "null#null";
Class<?>[] parameterTypes = new Class[] { String.class, String.class };
Class<?>[] parameterTypes = new Class<?>[] { String.class, String.class };

when(context.getSplitBy()).thenReturn("#");

Expand All @@ -419,7 +419,7 @@ public void testConvertShouldParseNullValuesAsStringIfSettingsConvertNullsIsFals
public void testConvertShouldParseNullValuesAsNullObjectIfSettingsConvertNullsIsTrue() {
// Given:
String data = "null,null,foo";
Class<?>[] parameterTypes = new Class[] { String.class, String.class, String.class };
Class<?>[] parameterTypes = new Class<?>[] { String.class, String.class, String.class };

when(context.getSplitBy()).thenReturn(",");
when(context.isConvertNulls()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import com.tngtech.junit.dataprovider.convert.SingleArgConverter;
import com.tngtech.junit.dataprovider.convert.StringConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.tngtech.junit.dataprovider.convert.ConverterContext;
import com.tngtech.junit.dataprovider.convert.DataConverter;
import com.tngtech.junit.dataprovider.format.DataProviderTestNameFormatter;
import com.tngtech.junit.dataprovider.resolver.DataProviderResolverContext;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.tngtech.java.junit.dataprovider.common.Preconditions.checkArgument;
import static com.tngtech.java.junit.dataprovider.common.Preconditions.checkNotNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

Expand Down Expand Up @@ -91,14 +92,25 @@ public String getName() {
}

try {
return nameFormatter.newInstance().format(getMethod(), idx, Arrays.asList(parameters));
return nameFormatter.getDeclaredConstructor().newInstance().format(getMethod(), idx,
Arrays.asList(parameters));
} catch (InstantiationException e) {
throw new IllegalStateException(String
.format("Could not instantiate name formatter using default constructor '%s'.", nameFormatter),
e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(
String.format("Default constructor not accessable of name formatter '%s'.", nameFormatter), e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(String.format("Default constructor of name formatter '%s' has thrown: %s",
nameFormatter, e.getMessage()), e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
String.format("Default constructor not found for name formatter '%s'.", nameFormatter), e);
} catch (Exception e) {
throw new IllegalStateException(String.format(
"Unexpected exception while finding and invoking default constructor of name formatter '%s': %s",
nameFormatter, e.getMessage()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.runners.model.FrameworkMethod;
Expand Down Expand Up @@ -46,11 +45,8 @@ private Method getMethodInt(Class<?> clazz, String methodName) {

// -- helper methods to create arrays, lists etc. ------------------------------------------------------------------

protected <T> List<T> list(T... ts) {
return Arrays.asList(ts);
}

protected <T> List<T[]> listOfArrays(T[]... arrays) {
@SafeVarargs
protected final <T> List<T[]> listOfArrays(T[]... arrays) {
List<T[]> result = new ArrayList<T[]>();
for (T[] array : arrays) {
result.add(array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.junit.runner.manipulation.Filter;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import com.tngtech.java.junit.dataprovider.internal.placeholder.BasePlaceholder;

Expand Down
Loading

0 comments on commit ce7ebd8

Please sign in to comment.