How to return different values with the same method call in the same class in a loop?

24 Views Asked by At

I am looping over a list table names to do the following

  1. Call describe table to check if the table exists
  2. If the table doesn't exist, throw ResourceNotFoundException.
  3. Call createTable method to create the table
  4. Call describe table to check if the table is created and is active.
  5. If not active, wait.

After the tables have been successfully created I want to change some properties of the table too.

So now the issue I'm facing is with unit tests.

I need to do these two

when(ddbClient.describeTable)
    .thenThrow(ResourceNotFoundException.class)
    .thenReturn(mockTableDescription);

But this only throws the exception. Is it because I have a loop? How exactly am I supposed write this test?

0

There are 0 best solutions below