本文整理汇总了Java中spock.lang.Specification类的典型用法代码示例。如果您正苦于以下问题:Java Specification类的具体用法?Java Specification怎么用?Java Specification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Specification类属于spock.lang包,在下文中一共展示了Specification类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClassModel
import spock.lang.Specification; //导入依赖的package包/类
ClassModel(ASTNodeFactory astNodeFactory, String className, Type superClassType, PackageDeclaration packageDeclaration,
List<FieldDeclaration> fields, List<MethodModel> methods, List<ImportDeclaration> imports,
List<TypeModel> innerTypes, List<ASTNode> modifiers) {
groovism = provide();
this.className = className;
this.packageDeclaration = packageDeclaration;
this.fields = fieldDeclarations(fields);
this.methods = unmodifiableList(new LinkedList<>(methods));
this.modifiers = unmodifiableList(new LinkedList<>(modifiers));
this.imports = imports;
this.innerTypes = unmodifiableList(new LinkedList<>(innerTypes));
if (isTestClass(methods)) {
this.superClassType = Optional.of(astNodeFactory.simpleType(Specification.class.getSimpleName()));
imports.add(0, astNodeFactory.importDeclaration(Specification.class));
} else {
this.superClassType = Optional.ofNullable(superClassType);
}
}
示例2: beforeTestMethod
import spock.lang.Specification; //导入依赖的package包/类
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
final Object testInstance = testContext.getTestInstance();
if (!(testInstance instanceof Specification)) {
return;
}
final Specification specification = (Specification) testInstance;
final List<Object> mocks = new LinkedList<>();
final ApplicationContext applicationContext = testContext.getApplicationContext();
final DoubleRegistry doubleRegistry = applicationContext.getBean(DoubleRegistry.BEAN_NAME, DoubleRegistry.class);
for (DoubleDefinition doubleDefinition : doubleRegistry.doublesSearch()) {
final Optional<Object> doubleBean = tryToGetBean(applicationContext, doubleDefinition);
doubleBean.ifPresent(bean -> {
mocks.add(bean);
mockUtil.attachMock(bean, specification);
});
}
testContext.setAttribute(MOCKED_BEANS_NAMES, mocks);
}
示例3: setupClasslist
import spock.lang.Specification; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void setupClasslist(){
classnameCombo.removeAllItems();
methodName.removeAllItems();
try
{
List<String> classList;
classList = ClassFinder.findClassesThatExtend(SPATHS, new Class [] {Specification.class});
ClassFilter filter = new ClassFilter();
filter.setPackages(JOrphanUtils.split(filterpkg.getText(), ",")); //$NON-NLS-1$
// change the classname drop down
Object[] clist = filter.filterArray(classList);
for (int idx=0; idx < clist.length; idx++) {
classnameCombo.addItem(clist[idx]);
}
}
catch (IOException e)
{
log.error("Exception getting interfaces.", e);
}
}
示例4: create
import spock.lang.Specification; //导入依赖的package包/类
@Override public Object create(IMockConfiguration configuration, Specification specification) {
for (IMockFactory factory : mockFactories) {
if (factory.canCreate(configuration)) {
return factory.create(configuration, specification);
}
}
throw new InternalSpockError("No matching mock factory found");
}
示例5: createInternal
import spock.lang.Specification; //导入依赖的package包/类
private Object createInternal(IMockConfiguration configuration, Specification specification, ClassLoader classLoader) {
if (Modifier.isFinal(configuration.getType().getModifiers())) {
throw new CannotCreateMockException(configuration.getType(),
" because Java mocks cannot mock final classes. If the code under test is written in Groovy, use a Groovy mock.");
}
if (configuration.isGlobal()) {
throw new CannotCreateMockException(configuration.getType(),
" because Java mocks cannot mock globally. If the code under test is written in Groovy, use a Groovy mock.");
}
MetaClass mockMetaClass = GroovyRuntimeUtil.getMetaClass(configuration.getType());
IProxyBasedMockInterceptor interceptor = new JavaMockInterceptor(configuration, specification, mockMetaClass);
return ProxyBasedMockFactory.INSTANCE.create(configuration.getType(), Collections.<Class<?>>emptyList(),
configuration.getConstructorArgs(), interceptor, classLoader);
}
示例6: initializeTestObject
import spock.lang.Specification; //导入依赖的package包/类
/**
* Initialize test object
*/
private void initializeTestObject() {
String rlabel = getConstructorString();
if (rlabel.length()== 0) {
rlabel = SpockSampler.class.getName();
}
this.testCase = (Specification) getClassInstance(className, rlabel);
if (this.testCase != null){
initMethodObjects(this.testCase);
}
}
示例7: create
import spock.lang.Specification; //导入依赖的package包/类
@Override public Object create(IMockConfiguration configuration, Specification specification) {
return createInternal(configuration, specification, specification.getClass().getClassLoader());
}