Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
How to do integ test using mockito

I have following two methods which i want to test

public class Orders {
    private final LambdaLogger logger;
    private final DynamoDBMapper dynamoDBMapper;

    public Orders(LambdaLogger logger, AmazonDynamoDB amazonDynamoDB){
        this.logger = logger;
        this.dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
    }

    public List<Orders> getOrders(){
        logger.log("getting all orders");

        DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
                .withProjectionExpression("OrderId");
        logger.log("Expression created");

        PaginatedScanList<Orders> scan = dynamoDBMapper.scan(Orders.class, scanExpression);

        return scan.stream()
                .collect(Collectors.toList());
    }
}

Now, I want to do testing using Mockito for this class. There are couple of things that I am confuse (or unable to get working).

First, DynamoDBMapper is being created using amazonDynamoDBClient. So if in my class i Mock AmazonDynamoDB, how the dynamoDBMapper would get created?

How would I test that my function is actually setting projection right?

How would i test on paginatedScanList?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It is violation of Dependency Injection principle that does not allow you to create a unit test.

Orders should not create any objects it should receive them as dependencies through constructor or setter methods. E.g. you could pass DynamoDBScanExpressionFactory and DynamoDBMapper to Orders' constructor. Then you would be able to mock them with mockito.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!