I tried to mock some maven classes.
I know I can mock an Interface or a class with maps
def projectMock = [ getBasedir: { new File("") } ] as MavenProject
But how do I mock a method that receives parameters?
I have tried to use “MockFor” for this:
def artifactFactoryMockContext = new MockFor(ArtifactFactory)
artifactFactoryMockContext.demand.createArtifact(1) {groupId, artifactId, version, classifier, type -> artifact }
def artifactFactory = artifactFactoryMockContext.proxyInstance()
But I get an UnsupportedOperationException. What am I doing wrong here?
Long as you’re ok using Groovy Map coercion for mocking instead of a framework, this kind of thing will work for you:
Now
fooMock.bar("arg1", "arg2")will return 42.