An attempt to expand Spock's appeal at work and run into this issue. Actually trying to write Unit Tests for the Groovy class, but one that calls Java. The static method invokes a private constructor. The code looks like this:
private MyConfigurator(String zkConnectionString){ solrZkClient = new SolrZkClient(zkConnectionString, 30000, 30000, new OnReconnect() { @Override public void command() { . . . } }); }
"SolrZkClient" is a third-party library (Apache). Since he is trying to connect to ZooKeeper, I would like to make fun of it for this Unit Test (instead of doing it internally as part of a unit test).
My test falls into the constructor without difficulty, but I can not get past this ctor:
def 'my test'() { when: MyConfigurator.staticMethodName('hostName:2181') then: // assertions }
Is there any way to do this?
java unit-testing groovy spock
Joeg
source share