Apply compiler conventions to test fixtures

This commit is contained in:
Sam Brannen 2020-02-07 11:04:03 +01:00
parent 45555f77a6
commit 51fa98a1b2
3 changed files with 18 additions and 16 deletions

View File

@ -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");
* 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"}.
*
* @author Brian Clozel
* @author Sam Brannen
*/
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
* 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 {
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
*/
private void applyJavaCompileConventions(Project project) {
@ -93,10 +95,12 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
compileTask.getOptions().setEncoding("UTF-8");
});
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 -> {
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
compileTask.getOptions().setEncoding("UTF-8");
});
}
}
}

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import java.util.HashMap;
*
* @author Rod Johnson
* @author Chris Beams
* @author Sam Brannen
*/
@SuppressWarnings("serial")
public class MethodCounter implements Serializable {
@ -39,15 +40,12 @@ public class MethodCounter implements Serializable {
}
protected void count(String methodName) {
Integer i = map.get(methodName);
i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1);
map.put(methodName, i);
map.merge(methodName, 1, (n, m) -> n + 1);
++allCount;
}
public int getCalls(String methodName) {
Integer i = map.get(methodName);
return (i != null ? i.intValue() : 0);
return map.getOrDefault(methodName, 0);
}
public int getCalls() {

View File

@ -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");
* 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 Float myFloat = new Float(0.0);
private Float myFloat = Float.valueOf(0.0f);
private Collection<? super Object> friends = new LinkedList<>();