Skip to content

NullPointerException in runtime for Random without static mocking #447

Closed

Description

@nikitavlaev

Description

Without mockito-inline force mocked statics generate NPE in runtime.

To Reproduce

Steps to reproduce the behavior:

Example:

  1. Open any project in IDEA
  2. Create such class:
import java.util.Random;

public class Rand {
    public boolean rand(int a) {
        Random r = new Random();
        return r.nextInt() > a;
    }
}
  1. Generate tests with "No static mocking"

Expected behavior

Tests are generated and run without errors.

Actual behavior

NPE is generated for tests where mock statics are forced.

Visual proofs (screenshots, logs, images)

image

Environment

Not suitable.

Additional context

This case should be treated exactly like force mocking case.

Activity

  1. self-assigned this
    on Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions