I am trying to mock Querybuilder and resolverfactory in my test class but I am getting null always.
Main class:
@Reference
QueryBuilder builder;
@Reference
ResourceResoloverFactory resolverFactory;
Test class:
@Mock
QueryBuilder builder;
setup(){
context.registerAdapter(ResourceResolver.class, QueryBuilder.class, builder);
when(builder.createQuery(any(PredicateGroup.class), any(Session.class))).thenReturn(query);
}
Suggest me how to mock @Reference objects in mockito.
Note: I am using Junit4 and mokito and AEM 6.2.
Solved! Go to Solution.
Views
Replies
Total Likes
Inside setup() add below line first and then use when
Whitebox.setInternalState(mainClassObject, "builder", builder);
This will initialise builder with mock builder in that mainClassObject.
Views
Replies
Total Likes
Inside setup() add below line first and then use when
Whitebox.setInternalState(mainClassObject, "builder", builder);
This will initialise builder with mock builder in that mainClassObject.
Views
Replies
Total Likes
Views
Replies
Total Likes
It seems that you just register adapters, but not services.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies