Skip to content

NullPointerException in runtime for Random without static mocking #447

Closed
@nikitavlaev

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.

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