### Question:
CloudwatchMetadataHandler extends MetadataHandler { @Override public ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest listSchemasRequest) throws TimeoutException { DescribeLogGroupsRequest request = new DescribeLogGroupsRequest(); DescribeLogGroupsResult result; List<String> schemas = new ArrayList<>(); do { if (schemas.size() > MAX_RESULTS) { throw new RuntimeException("Too many log groups, exceeded max metadata results for schema count."); } result = invoker.invoke(() -> awsLogs.describeLogGroups(request)); result.getLogGroups().forEach(next -> schemas.add(next.getLogGroupName().toLowerCase())); request.setNextToken(result.getNextToken()); logger.info("doListSchemaNames: Listing log groups {} {}", result.getNextToken(), schemas.size()); } while (result.getNextToken() != null); return new ListSchemasResponse(listSchemasRequest.getCatalogName(), schemas); } CloudwatchMetadataHandler(); @VisibleForTesting protected  CloudwatchMetadataHandler(AWSLogs awsLogs,
            EncryptionKeyFactory keyFactory,
            AWSSecretsManager secretsManager,
            AmazonAthena athena,
            String spillBucket,
            String spillPrefix); @Override ListSchemasResponse doListSchemaNames(BlockAllocator blockAllocator, ListSchemasRequest listSchemasRequest); @Override ListTablesResponse doListTables(BlockAllocator blockAllocator, ListTablesRequest listTablesRequest); @Override GetTableResponse doGetTable(BlockAllocator blockAllocator, GetTableRequest getTableRequest); @Override void enhancePartitionSchema(SchemaBuilder partitionSchemaBuilder, GetTableLayoutRequest request); @Override void getPartitions(BlockWriter blockWriter, GetTableLayoutRequest request, QueryStatusChecker queryStatusChecker); @Override GetSplitsResponse doGetSplits(BlockAllocator allocator, GetSplitsRequest request);  }### Answer:
@Test public void doListSchemaNames() throws TimeoutException { logger.info("doListSchemas - enter"); when(mockAwsLogs.describeLogGroups(any(DescribeLogGroupsRequest.class))).thenAnswer((InvocationOnMock invocationOnMock) -> { DescribeLogGroupsRequest request = (DescribeLogGroupsRequest) invocationOnMock.getArguments()[0]; DescribeLogGroupsResult result = new DescribeLogGroupsResult(); Integer nextToken; if (request.getNextToken() == null) { nextToken = 1; } else if (Integer.valueOf(request.getNextToken()) < 3) { nextToken = Integer.valueOf(request.getNextToken()) + 1; } else { nextToken = null; } List<LogGroup> logGroups = new ArrayList<>(); if (request.getNextToken() == null || Integer.valueOf(request.getNextToken()) < 3) { for (int i = 0; i < 10; i++) { LogGroup nextLogGroup = new LogGroup(); nextLogGroup.setLogGroupName("schema-" + String.valueOf(i)); logGroups.add(nextLogGroup); } } result.withLogGroups(logGroups); if (nextToken != null) { result.setNextToken(String.valueOf(nextToken)); } return result; }); ListSchemasRequest req = new ListSchemasRequest(identity, "queryId", "default"); ListSchemasResponse res = handler.doListSchemaNames(allocator, req); logger.info("doListSchemas - {}", res.getSchemas()); assertTrue(res.getSchemas().size() == 30); verify(mockAwsLogs, times(4)).describeLogGroups(any(DescribeLogGroupsRequest.class)); verifyNoMoreInteractions(mockAwsLogs); logger.info("doListSchemas - exit"); }