DynamoDBManager { public static boolean doesTableExist(final AmazonDynamoDB dynamoDB, final String tableName) { try { dynamoDB.describeTable(tableName); return true; } catch (final ResourceNotFoundException e) { return false; } catch (final AmazonClientException e) { LOGGER.severe(e.getMessage()); return false; } } private  DynamoDBManager(); static TableDescription createTable(final AmazonDynamoDB dynamoDB, final CreateTableRequest request); static boolean doesTableExist(final AmazonDynamoDB dynamoDB, final String tableName); static TableStatus getTableStatus(final AmazonDynamoDB dynamoDB, final String tableName); static void waitForTableToBecomeActive(final AmazonDynamoDB dynamoDB, final String tableName);  }
@Test public void testTableDoesNotExist() { EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException("")); PowerMock.replayAll(); assertFalse(DynamoDBManager.doesTableExist(dynamoDB, tableName)); PowerMock.verifyAll(); }
@Test public void testTableExistException() { EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new AmazonClientException("")); PowerMock.replayAll(); assertFalse(DynamoDBManager.doesTableExist(dynamoDB, tableName)); PowerMock.verifyAll(); }
@Test public void testTableExists() { final DescribeTableResult result = new DescribeTableResult(); dynamoDB.describeTable(tableName); PowerMock.expectLastCall().andReturn(result); PowerMock.replayAll(); assertTrue(DynamoDBManager.doesTableExist(dynamoDB, tableName)); PowerMock.verifyAll(); }