Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda