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

Mockito cannot mock this class:.. Java 11 #184

Closed
TheGitHubGuy1 opened this issue Jun 10, 2020 · 1 comment
Closed

Mockito cannot mock this class:.. Java 11 #184

TheGitHubGuy1 opened this issue Jun 10, 2020 · 1 comment

Comments

@TheGitHubGuy1
Copy link

TheGitHubGuy1 commented Jun 10, 2020

gradle.build

// **Testing**
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testCompile "org.testcontainers:junit-jupiter:1.14.1"
testCompile "org.testcontainers:testcontainers:1.14.1"
testCompile "org.testcontainers:postgresql:1.14.1"
testAnnotationProcessor platform("io.micronaut:micronaut-bom:1.3.6")
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testAnnotationProcessor "org.projectlombok:lombok:1.18.12"
testImplementation platform("io.micronaut:micronaut-bom:1.3.6")
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "io.micronaut.test:micronaut-test-junit5"
// Mockito
testImplementation "org.mockito:mockito-junit-jupiter:2.22.0"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
Error instantiating bean of type x.x.x
Mockito cannot mock this class: x.x.x

Java               : 11
JVM vendor name    : JetBrains s.r.o
JVM vendor version : 11.0.4+10-b304.77
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 11.0.4+10-b304.77
JVM info           : mixed mode
OS name            : Linux
OS version         : 5.3.0-53-generic

Refers to instances of @MockBean

    @MockBean(X.class)
       X x(){
        return mock(X.class);
    }

Works with Java8

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

Suspect related to mockito-core version being < 2.22 after a little googling.
Imported testCompile group: 'org.mockito', name: 'mockito-core', version: '2.22.0
Didn't resolve the issue

@TheGitHubGuy1
Copy link
Author

Looks like upgrading to latest mockito-junit-jupiter updated mockito-core to 3.3.3 too.

// https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.3.3'

Solved it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant