在类路径上除了cglib外还有objensis,as
Michael Easter
正确地说,您的示例是有效的。不过,不需要使用bytebuddy。
另请参见
Spock manual
.
<!-- (...) -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<!-- (...) -->
package de.scrum_master.stackoverflow;
import org.modelmapper.AbstractConverter;
public class MyConverter extends AbstractConverter<Integer, String> {
@Override
protected String convert(Integer source) {
return source.toString();
}
}
package de.scrum_master.stackoverflow
import spock.lang.Specification
class MyConverterTest extends Specification {
def "test"() {
given:
def myConverter = Mock(MyConverter) {
convert(_) >>> ["one", "two"] >> { callRealMethod() }
}
expect:
myConverter.convert(11) == "one"
myConverter.convert(22) == "two"
myConverter.convert(11) == "11"
myConverter.convert(22) == "22"
}
}