Skip to content
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

Bump versions.errorprone from 2.10.0 to 2.12.1 #2608

Merged
merged 5 commits into from Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions build.gradle
Expand Up @@ -52,8 +52,10 @@ allprojects { proj ->
mavenCentral()
google()
}
plugins.withId('java') {
proj.apply from: "$rootDir/gradle/errorprone.gradle"
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
plugins.withId('java') {
proj.apply from: "$rootDir/gradle/errorprone.gradle"
}
}
tasks.withType(JavaCompile) {
//I don't believe those warnings add value given modern IDEs
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Expand Up @@ -6,7 +6,7 @@ def versions = [:]

versions.bytebuddy = '1.12.7'
versions.junitJupiter = '5.8.2'
versions.errorprone = '2.10.0'
versions.errorprone = '2.12.1'

libraries.junit4 = 'junit:junit:4.13.2'
libraries.junitJupiterApi = "org.junit.jupiter:junit-jupiter-api:${versions.junitJupiter}"
Expand Down
7 changes: 6 additions & 1 deletion settings.gradle.kts
Expand Up @@ -14,11 +14,16 @@ include("inline",
"junitJupiterInlineMockMakerExtensionTest",
"module-test",
"memory-test",
"errorprone",
"junitJupiterParallelTest",
"osgi-test",
"bom")

if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11)) {
include("errorprone")
} else {
logger.info("Not including errorprone, which requires minimum JDK 11+")
}

if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17) && (System.getenv("ANDROID_SDK_ROOT") != null || File(".local.properties").exists())) {
include("androidTest")
} else {
Expand Down
Expand Up @@ -6,6 +6,7 @@

import java.io.Serializable;

import java.util.Objects;
import org.mockito.ArgumentMatcher;

public class EqualsWithDelta implements ArgumentMatcher<Number>, Serializable {
Expand All @@ -24,7 +25,7 @@ public boolean matches(Number actual) {
return false;
}

if (wanted == actual) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code was not incorrect due to the subsequent range check. An alternative to this change would be to suppress the DoubleBraceInitialization check on this method. However, simply using .equals is likely less surprising.

if (Objects.equals(wanted, actual)) {
return true;
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
import static org.mockito.internal.matchers.text.ValuePrinter.print;

import java.util.LinkedHashMap;

import java.util.Map;
import org.junit.Test;

public class ValuePrinterTest {
Expand All @@ -24,29 +24,23 @@ public void prints_values() {
assertThat(print(3.14d)).isEqualTo("3.14d");
assertThat(print(3.14f)).isEqualTo("3.14f");
assertThat(print(new int[] {1, 2})).isEqualTo("[1, 2]");
assertThat(
print(
new LinkedHashMap<String, Object>() {
{
put("foo", 2L);
}
}))
.isEqualTo("{\"foo\" = 2L}");
assertThat(
print(
new LinkedHashMap<String, Object>() {
{
put("int passed as hex", 0x01);
put("byte", (byte) 0x01);
put("short", (short) 2);
put("int", 3);
put("long", 4L);
put("float", 2.71f);
put("double", 3.14d);
}
}))

Map<String, Object> map1 = new LinkedHashMap<>();
map1.put("foo", 2L);
assertThat(print(map1)).isEqualTo("{\"foo\" = 2L}");

Map<String, Object> map2 = new LinkedHashMap<>();
map2.put("int passed as hex", 0x01);
map2.put("byte", (byte) 0x01);
map2.put("short", (short) 2);
map2.put("int", 3);
map2.put("long", 4L);
map2.put("float", 2.71f);
map2.put("double", 3.14d);
assertThat(print(map2))
.isEqualTo(
"{\"int passed as hex\" = 1, \"byte\" = (byte) 0x01, \"short\" = (short) 2, \"int\" = 3, \"long\" = 4L, \"float\" = 2.71f, \"double\" = 3.14d}");

assertTrue(print(new UnsafeToString()).contains("UnsafeToString"));
assertThat(print(new ToString())).isEqualTo("ToString");
assertThat(print(new FormattedText("formatted"))).isEqualTo("formatted");
Expand Down
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert;
import org.junit.Test;
Expand Down Expand Up @@ -307,20 +306,14 @@ private static <T> InterceptedInvocation invocationMethodWithVarArgs(final T[] o
should_return_a_empty_map_that_has_been_defined_with_method_generic_and_provided_in_var_args()
throws Throwable {

final Map<String, String> map1 =
new HashMap<String, String>() {
{
put("key-1", "value-1");
put("key-2", "value-2");
}
};
final Map<String, String> map2 =
new HashMap<String, String>() {
{
put("key-3", "value-1");
put("key-4", "value-2");
}
};
final Map<String, String> map1 = new HashMap<>();
map1.put("key-1", "value-1");
map1.put("key-2", "value-2");

final Map<String, String> map2 = new HashMap<>();
map2.put("key-3", "value-1");
map2.put("key-4", "value-2");

Answer<Object> answer = new ReturnsSmartNulls();

Object smartNull = answer.answer(invocationMethodWithVarArgs(new Map[] {map1, map2}));
Expand Down
45 changes: 18 additions & 27 deletions src/test/java/org/mockito/internal/util/PlatformTest.java
Expand Up @@ -8,7 +8,6 @@

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

// Possible description on a IBM J9 VM (see #801)
Expand Down Expand Up @@ -75,23 +74,19 @@ public void should_parse_open_jdk_string_and_report_wether_below_or_nut_update_4
// https://stackoverflow.com/questions/35844985/how-do-we-get-sr-and-fp-of-ibm-jre-using-java
// -
// https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.80.doc/user/build_number.html
Map<String, Boolean> versions =
new HashMap<String, Boolean>() {
{
put("1.8.0_92-b14", false);
put("1.8.0-b24", true);
put("1.8.0_5", true);
put("1.8.0b5_u44", true);
put("1.8.0b5_u92", false);
put("1.7.0_4", false);
put("1.4.0_03-b04", false);
put("1.4.0_03-ea-b01", false);
put("pxi3270_27sr4-20160303_03 (SR4)", false);
put("pwi3260sr11-20120412_01 (SR11)", false);
put("pwa6480sr1fp10-20150711_01 (SR1 FP10)", false);
put("null", false);
}
};
Map<String, Boolean> versions = new HashMap<>();
versions.put("1.8.0_92-b14", false);
versions.put("1.8.0-b24", true);
versions.put("1.8.0_5", true);
versions.put("1.8.0b5_u44", true);
versions.put("1.8.0b5_u92", false);
versions.put("1.7.0_4", false);
versions.put("1.4.0_03-b04", false);
versions.put("1.4.0_03-ea-b01", false);
versions.put("pxi3270_27sr4-20160303_03 (SR4)", false);
versions.put("pwi3260sr11-20120412_01 (SR11)", false);
versions.put("pwa6480sr1fp10-20150711_01 (SR1 FP10)", false);
versions.put("null", false);

assertPlatformParsesCorrectlyVariousVersionScheme(versions);
}
Expand Down Expand Up @@ -134,15 +129,11 @@ public void should_parse_open_jdk9_string() {
// java.specification.version 1.9 9
// java.vm.specification.version 1.9 9
//
Map<String, Boolean> versions =
new HashMap<String, Boolean>() {
{
put("9-ea+73", false);
put("9+100", false);
put("9.1.2+62", false);
put("9.0.1+20", false);
}
};
Map<String, Boolean> versions = new HashMap<>();
versions.put("9-ea+73", false);
versions.put("9+100", false);
versions.put("9.1.2+62", false);
versions.put("9.0.1+20", false);

assertPlatformParsesCorrectlyVariousVersionScheme(versions);
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;

import org.assertj.core.api.Assertions;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.Before;
import org.junit.Test;
import org.mockito.exceptions.base.MockitoException;
Expand Down Expand Up @@ -248,34 +249,34 @@ public void shouldNotAllowSettingNullThrowableArray() {
.hasMessageContaining("Cannot stub with null throwable");
}

@Test
public void shouldNotAllowSettingNullThrowableClass() {
assertThatThrownBy(
() -> {
when(mock.isEmpty()).thenThrow((Class) null);
})
private void assertExceptionTypeCanNotBeNull(ThrowingCallable throwingCallable) {
assertThatThrownBy(throwingCallable)
.isInstanceOf(MockitoException.class)
.hasMessageContaining("Exception type cannot be null");
}

@Test
public void shouldNotAllowSettingNullThrowableClass() {
assertExceptionTypeCanNotBeNull(
() -> {
when(mock.isEmpty()).thenThrow((Class) null);
});
}

@Test
public void shouldNotAllowSettingNullThrowableClasses() {
assertThatThrownBy(
() -> {
when(mock.isEmpty()).thenThrow(RuntimeException.class, (Class[]) null);
})
.isInstanceOf(MockitoException.class)
.hasMessageContaining("Exception type cannot be null");
assertExceptionTypeCanNotBeNull(
() -> {
when(mock.isEmpty()).thenThrow(RuntimeException.class, (Class[]) null);
});
}

@Test
public void shouldNotAllowSettingNullVarArgThrowableClass() {
assertThatThrownBy(
() -> {
when(mock.isEmpty()).thenThrow(RuntimeException.class, (Class) null);
})
.isInstanceOf(MockitoException.class)
.hasMessageContaining("Exception type cannot be null");
assertExceptionTypeCanNotBeNull(
() -> {
when(mock.isEmpty()).thenThrow(RuntimeException.class, (Class) null);
});
}

@Test
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class MockitoAnyIncorrectPrimitiveType extends AbstractMockitoAnyForPrimi
};

private static final Matcher<ExpressionTree> METHOD_MATCHER =
staticMethod().onClassAny(CLASS_NAMES).withNameMatching(METHOD_NAME_PATTERN).withParameters();
staticMethod().onClassAny(CLASS_NAMES).withNameMatching(METHOD_NAME_PATTERN).withNoParameters();

@Override
protected Matcher<? super MethodInvocationTree> matcher() {
Expand Down