yongjhih / mocker
posted
Category: Utils
Minimum SDK Level: None (1 | 1.0)

Badge

View in Github Github project information
Starred: 0
Forks: 0
Watchers: 0
Open Issues: 0

Snapshot pictures

No snapshot for this library yet.

Description

Usage

mock():

ParseUser mockUser = mocker(ParseUser.class).mock();

Infer casting:

// Before: ParseQuery<ParseUser> mockQuery = (ParseQuery<ParseUser>) Mockito.mock(ParseQuery.class);
// After:
ParseQuery<ParseUser> mockQuery = mocker(ParseQuery.class).mock();

when-thenReturn:

ParseUser mockUser = mocker(ParseUser.class)
    .when(user -> user.getObjectId()).thenReturn(user -> "1_" + user.hashCode());
    .mock();

Multiple when-thenReturn:

ParseQuery<ParseUser> mockQuery = mocker(ParseQuery.class)
    .when(query -> query.countInBackground()).thenReturn(query -> Task.forResult(users.size()))
    .when(query -> query.findInBackground()).thenReturn(query -> Task.forResult(users))
    .when(query -> query.setSkip(any(int.class))).thenReturn(query -> null)
    .when(query -> query.setLimit(any(int.class))).thenReturn(query -> null)
    .mock();
0

See also