googleapis / googleapis/java-genai

Mocking support

Open
#437 1 comment 4 reactions 2 assignees Claimed by @hemasekhar-p View on GitHub
priority: p3 type: feature request
Dominant language
Java
Stars
397
Forks
125
Avg merge
2d 8h
Merged PRs (30d)
41

Description

Due to the design of the GenAI Client() class it isn't possible to mock it for most use cases.

For example (with Mockito):

```
Client clientMock = mock(Client.class);
when(clientMock.models).thenReturn(mock(Models.class));
```
A simple scenario such as this won't work because the `models` property in Client is final and can only be set through constructors that I also can't override because the class is marked as final. It might be possible to use `mockito-inline` but this isn't ideal for a number of reasons.

The idiomatic way for the Client class to be defined in Java is for models to be accessed via a getter which would also support basic mocking but other ways to support mocking a Client would be welcome.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.