'Java Unit testing a gRPC ServerStream

I have some code that iterates over com.google.api.gax.rpc.ServerStream and performs some logic. I want to write a unit test that tests that logic. How do I mock a ServerStream with data for testing?

 Query query = Query.create(tvBigtableConfig.getTable()).prefix(CustomerType.B2B.getType()).filter(filterChain);
        ServerStream<Row> rows = dataClient.readRows(query);

        if (!ObjectUtils.isEmpty(rows)) {
            String currentKey = null;
            Map<String, String> groupData = new HashMap<>();
            .....
            .....

How can I create a ServerStream in my unit test to test this logic?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source