Apply compiler conventions to test fixtures
This commit is contained in:
parent
45555f77a6
commit
51fa98a1b2
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -33,6 +33,7 @@ import org.gradle.api.tasks.compile.JavaCompile;
|
||||||
* with a dedicated property on the CLI: {@code "./gradlew test -PjavaSourceVersion=11"}.
|
* with a dedicated property on the CLI: {@code "./gradlew test -PjavaSourceVersion=11"}.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class CompilerConventionsPlugin implements Plugin<Project> {
|
public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
|
|
@ -40,13 +41,13 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||||
* The project property that can be used to switch the Java source
|
* The project property that can be used to switch the Java source
|
||||||
* compatibility version for building source and test classes.
|
* compatibility version for building source and test classes.
|
||||||
*/
|
*/
|
||||||
public static String JAVA_SOURCE_VERSION_PROPERTY = "javaSourceVersion";
|
public static final String JAVA_SOURCE_VERSION_PROPERTY = "javaSourceVersion";
|
||||||
|
|
||||||
public static JavaVersion DEFAULT_COMPILER_VERSION = JavaVersion.VERSION_1_8;
|
public static final JavaVersion DEFAULT_COMPILER_VERSION = JavaVersion.VERSION_1_8;
|
||||||
|
|
||||||
private static List<String> COMPILER_ARGS;
|
private static final List<String> COMPILER_ARGS;
|
||||||
|
|
||||||
private static List<String> TEST_COMPILER_ARGS;
|
private static final List<String> TEST_COMPILER_ARGS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
List<String> commonCompilerArgs = Arrays.asList(
|
List<String> commonCompilerArgs = Arrays.asList(
|
||||||
|
|
@ -72,7 +73,8 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the common Java compiler options for sources and test sources.
|
* Applies the common Java compiler options for main sources, test fixture sources, and
|
||||||
|
* test sources.
|
||||||
* @param project the current project
|
* @param project the current project
|
||||||
*/
|
*/
|
||||||
private void applyJavaCompileConventions(Project project) {
|
private void applyJavaCompileConventions(Project project) {
|
||||||
|
|
@ -93,10 +95,12 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||||
compileTask.getOptions().setEncoding("UTF-8");
|
compileTask.getOptions().setEncoding("UTF-8");
|
||||||
});
|
});
|
||||||
project.getTasks().withType(JavaCompile.class)
|
project.getTasks().withType(JavaCompile.class)
|
||||||
.matching(javaCompile -> javaCompile.getName().equals(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME))
|
.matching(javaCompile -> javaCompile.getName().equals(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
|
||||||
|
|| javaCompile.getName().equals("compileTestFixturesJava"))
|
||||||
.forEach(compileTask -> {
|
.forEach(compileTask -> {
|
||||||
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
|
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
|
||||||
compileTask.getOptions().setEncoding("UTF-8");
|
compileTask.getOptions().setEncoding("UTF-8");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.HashMap;
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class MethodCounter implements Serializable {
|
public class MethodCounter implements Serializable {
|
||||||
|
|
@ -39,15 +40,12 @@ public class MethodCounter implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void count(String methodName) {
|
protected void count(String methodName) {
|
||||||
Integer i = map.get(methodName);
|
map.merge(methodName, 1, (n, m) -> n + 1);
|
||||||
i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1);
|
|
||||||
map.put(methodName, i);
|
|
||||||
++allCount;
|
++allCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCalls(String methodName) {
|
public int getCalls(String methodName) {
|
||||||
Integer i = map.get(methodName);
|
return map.getOrDefault(methodName, 0);
|
||||||
return (i != null ? i.intValue() : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCalls() {
|
public int getCalls() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -75,7 +75,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||||
|
|
||||||
private Date date = new Date();
|
private Date date = new Date();
|
||||||
|
|
||||||
private Float myFloat = new Float(0.0);
|
private Float myFloat = Float.valueOf(0.0f);
|
||||||
|
|
||||||
private Collection<? super Object> friends = new LinkedList<>();
|
private Collection<? super Object> friends = new LinkedList<>();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue