简体   繁体   中英

Groovy Spock test for Java class - how to mock a Clob

I'm using Groovy's Spock framework to write a unit test for a Java class that gets a Clob from a database, retrieves an InputStream from that Clob (with java.sql.Clob.getAsciiStream() method) and then passes that InputStream to an ObjectMapper.readValue() method (from Jackson Databind library). Any ideas on how to mock that behavior? I've seen a java library that has a MockClob class, but I want to do this using Spock. The code is something like this:

InputStream inputStream = database.getClob().getAsciiStream();
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new ObjectMapper();
objectMapper.readValue(inputStream);

I found a workaround by creating an instance of a database-specific Clob implementation. The class is DB2ConnectionlessClob for ibm-db2 database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM