Skip to content

Commit

Permalink
Run CI on Java 17 (#2417)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafael Winterhalter <rafael.wth@gmail.com>
  • Loading branch information
TimvdLippe and raphw committed Sep 24, 2021
1 parent 99f8a62 commit 6a50cc4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -26,7 +26,7 @@ jobs:
# Definition of the build matrix
strategy:
matrix:
java: [8, 11, 15]
java: [8, 11, 17]
mock-maker: ['mock-maker-default', 'mock-maker-inline']

# All build steps
Expand All @@ -41,7 +41,7 @@ jobs:
- name: 2. Set up Java ${{ matrix.java }}
uses: actions/setup-java@v2
with:
distribution: 'adopt'
distribution: 'zulu'
java-version: ${{ matrix.java }}

- name: 3. Validate Gradle wrapper
Expand Down
2 changes: 1 addition & 1 deletion gradle/root/coverage.gradle
Expand Up @@ -19,7 +19,7 @@ task mockitoCoverage(type: JacocoReport) {
apply plugin: "jacoco"

jacoco {
toolVersion = '0.8.6'
toolVersion = '0.8.7'

if (currentProject != rootProject) { //already automatically enhanced in mockito main project as "java" plugin was applied before
applyTo test
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Expand Up @@ -18,7 +18,7 @@ include("inline",
"junitJupiterParallelTest",
"osgi-test")

if (System.getenv("ANDROID_SDK_ROOT") != null || File(".local.properties").exists()) {
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17) && (System.getenv("ANDROID_SDK_ROOT") != null || File(".local.properties").exists())) {
include("androidTest")
} else {
logger.info("Not including android test project due to missing SDK configuration")
Expand Down
Expand Up @@ -4,13 +4,6 @@
*/
package org.mockito.internal.creation.bytebuddy;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Observable;
import java.util.Observer;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.description.modifier.TypeManifestation;
Expand All @@ -19,6 +12,13 @@
import org.mockito.internal.creation.MockSettingsImpl;
import org.mockito.plugins.MockMaker;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Observable;
import java.util.Observer;

import static org.assertj.core.api.Assertions.assertThat;

public class SubclassByteBuddyMockMakerTest
extends AbstractByteBuddyMockMakerTest<SubclassByteBuddyMockMaker> {

Expand All @@ -35,22 +35,16 @@ public void is_type_mockable_excludes_primitive_wrapper_classes() {

@Test
public void is_type_mockable_excludes_sealed_classes() {
// is only supported on Java 17 and later
if (ClassFileVersion.ofThisVm().isAtMost(ClassFileVersion.JAVA_V16)) {
return;
}
DynamicType.Builder<Object> base = new ByteBuddy().subclass(Object.class);
DynamicType.Unloaded<Object> dynamic =
new ByteBuddy()
.subclass(Object.class)
.permittedSubclass(base.toTypeDescription())
.make();
DynamicType.Builder<?> base = new ByteBuddy().subclass(Object.class);
DynamicType.Builder<?> subclass =
new ByteBuddy().subclass(base.toTypeDescription()).merge(TypeManifestation.FINAL);
Class<?> type =
new ByteBuddy()
.subclass(base.toTypeDescription())
.merge(TypeManifestation.FINAL)
base.permittedSubclass(subclass.toTypeDescription())
.make()
.include(dynamic)
.include(subclass.make())
.load(null)
.getLoaded();
MockMaker.TypeMockability mockable = mockMaker.isTypeMockable(type);
Expand Down
Expand Up @@ -116,16 +116,16 @@ public void can_get_raw_type_from_ParameterizedType() {
public void can_get_type_variables_from_Class() {
assertThat(inferFrom(GenericsNest.class).actualTypeArguments().keySet())
.hasSize(1)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("K");
assertThat(inferFrom(ListOfNumbers.class).actualTypeArguments().keySet()).isEmpty();
assertThat(inferFrom(ListOfAnyNumbers.class).actualTypeArguments().keySet())
.hasSize(1)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("N");
assertThat(inferFrom(Map.class).actualTypeArguments().keySet())
.hasSize(2)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("K", "V");
assertThat(inferFrom(Serializable.class).actualTypeArguments().keySet()).isEmpty();
assertThat(inferFrom(StringList.class).actualTypeArguments().keySet()).isEmpty();
Expand Down Expand Up @@ -153,21 +153,21 @@ public void can_get_type_variables_from_ParameterizedType() {
.actualTypeArguments()
.keySet())
.hasSize(2)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("K", "V");
assertThat(
inferFrom(ListOfAnyNumbers.class.getGenericInterfaces()[0])
.actualTypeArguments()
.keySet())
.hasSize(1)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("E");
assertThat(
inferFrom(Integer.class.getGenericInterfaces()[0])
.actualTypeArguments()
.keySet())
.hasSize(1)
.extracting("name")
.extracting(TypeVariable::getName)
.contains("T");
assertThat(
inferFrom(StringBuilder.class.getGenericInterfaces()[0])
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.concurrent.Callable;

import net.bytebuddy.ClassFileVersion;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -31,6 +32,10 @@ public void reproduce_CCE_by_creating_a_mock_with_IMethods_before() throws Excep
@Test
public void check_that_mock_can_be_serialized_in_a_classloader_and_deserialized_in_another()
throws Exception {
// No longer supported starting with JDK 16+
if (!ClassFileVersion.ofThisVm().isAtMost(ClassFileVersion.JAVA_V16)) {
return;
}
byte[] bytes = create_mock_and_serialize_it_in_class_loader_A();

Object the_deserialized_mock = read_stream_and_deserialize_it_in_class_loader_B(bytes);
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/org/mockitoutil/SimpleSerializationUtil.java
Expand Up @@ -6,7 +6,12 @@

import static org.junit.Assert.assertNotNull;

import java.io.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public abstract class SimpleSerializationUtil {

Expand Down
1 change: 0 additions & 1 deletion subprojects/memory-test/memory-test.gradle
Expand Up @@ -15,5 +15,4 @@ tasks.javadoc.enabled = false

test {
maxHeapSize = "128m"
jvmArgs = ["-XX:MaxPermSize=128m"]
}

0 comments on commit 6a50cc4

Please sign in to comment.