I have aggregation method in service like following:
public List<Demo> demo() {
Aggregation aggre = Aggregation.newAggregation(
Aggregation.project("date").and(month("$date")).as("month"),
Aggregation.group("$month").count().as("count"),
project("count").and("month").previousOperation(),
Aggregation.match(where("month").is(2)));
return mongoTemplate.aggregate(aggre, "demo", Demo.class).getMappedResults();
}
How can I write a JUnit test case for the above method in spring boot?
I have tried using the following:
@Test
public void demoTest(){
List<Demo> items= demoService.demo();
Assert.assertEquals(1, items.size());
}
I have tried the above code but it throws a NullPointerException
. How can I solve this?