下面列出了怎么用org.junit.rules.ErrorCollector的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* check all properties of a component for i18n, check form i18n, check ComponentProperties title is i18n
*
* @param componentService where to get all the components
* @param errorCollector used to collect all errors at once. @see
* <a href="http://junit.org/apidocs/org/junit/rules/ErrorCollector.html">ErrorCollector</a>
* @deprecated use {@link PropertiesTestUtils#assertAlli18nAreSetup(DefinitionRegistryService, ErrorCollector)} and
* {@link #assertReturnProperties18nAreSet(DefinitionRegistryService, ErrorCollector)}
*/
@Deprecated
static public void testAlli18n(ComponentService componentService, ErrorCollector errorCollector) {
Set<ComponentDefinition> allComponents = componentService.getAllComponents();
for (ComponentDefinition cd : allComponents) {
ComponentProperties props = (ComponentProperties) PropertiesImpl.createNewInstance(cd.getPropertiesClass(), "root")
.init();
// check all properties
if (props != null) {
checkAllI18N(props, errorCollector);
} else {
System.out.println("No properties to check fo I18n for :" + cd.getName());
}
// check component definition title
errorCollector.checkThat(
"missing I18n property [" + cd.getTitle() + "] for definition [" + cd.getClass().getName() + "]",
cd.getTitle().contains("component."), is(false));
// check return properties i18n
checkAllPropertyI18n(cd.getReturnProperties(), cd, errorCollector);
}
}
public FakeWindmillServer(ErrorCollector errorCollector) {
workToOffer = new ConcurrentLinkedQueue<>();
dataToOffer = new ConcurrentLinkedQueue<>();
commitsReceived = new ConcurrentHashMap<>();
exceptions = new LinkedBlockingQueue<>();
expectedExceptionCount = new AtomicInteger();
this.errorCollector = errorCollector;
statsReceived = new ArrayList<>();
droppedStreamingCommits = new AtomicInteger();
}
static public void checkAllSchemaPathAreSchemaTypes(ComponentService service, ErrorCollector collector) {
Set<ComponentDefinition> allComponents = service.getAllComponents();
for (ComponentDefinition cd : allComponents) {
ComponentProperties properties = cd.createProperties();
if (properties instanceof FixedConnectorsComponentProperties) {
checkAllSchemaPathAreSchemaTypes((FixedConnectorsComponentProperties) properties, collector);
}
}
}
private static void checkAllConnector(FixedConnectorsComponentProperties fccp, ErrorCollector collector,
Set<PropertyPathConnector> allConnectors) {
for (PropertyPathConnector connector : allConnectors) {
NamedThing property = fccp.getProperty(connector.getPropertyPath());
collector.checkThat(property, notNullValue());
collector.checkThat(property, anyOf(instanceOf(Property.class), instanceOf(SchemaProperties.class)));
}
}
/**
* check all properties of a component for i18n, check form i18n, check ComponentProperties title is i18n
*
* @param componentService where to get all the components
* @param errorCollector used to collect all errors at once. @see
* <a href="http://junit.org/apidocs/org/junit/rules/ErrorCollector.html">ErrorCollector</a>
*/
static public void assertReturnProperties18nAreSet(DefinitionRegistryService definitionRegistry,
ErrorCollector errorCollector) {
Collection<ComponentDefinition> allComponents = definitionRegistry.getDefinitionsMapByType(ComponentDefinition.class)
.values();
for (ComponentDefinition cd : allComponents) {
// check return properties i18n
checkAllPropertyI18n(cd.getReturnProperties(), cd, errorCollector);
}
}
public static void checkAllPropertyI18n(Property<?>[] propertyArray, Object parent, ErrorCollector errorCollector) {
if (propertyArray != null) {
for (Property<?> prop : propertyArray) {
PropertiesTestUtils.chekProperty(errorCollector, prop, parent);
}
} // else no property to check so ignore.
}
void verifyAnnotationKeys(ErrorCollector collector) {
collector.checkThat("No annotation keys registered.", traceMetadataSetupContext.dynamicAnnotationKeys, is(not(empty())));
for (Map.Entry<Integer, List<String>> e : annotationKeyNamesByCode.entrySet()) {
Integer annotationKeyCode = e.getKey();
List<String> annotationKeyNames = e.getValue();
collector.checkThat("Duplicate annotation keys. Code : " + annotationKeyCode + ", names : " + annotationKeyNames,
annotationKeyNames, hasSize(1));
}
}
@Async
public void getStringInFuture(ErrorCollector collector) {
final String backendValue = traceeBackend.get("myKey");
collector.checkThat(backendValue, notNullValue());
collector.checkThat(oldVals, not(hasItem(backendValue)));
oldVals.add(backendValue);
invocationCount.incrementAndGet();
}
static public void checkAllSchemaPathAreSchemaTypes(FixedConnectorsComponentProperties fccp, ErrorCollector collector) {
Set<PropertyPathConnector> allConnectors = fccp.getAllSchemaPropertiesConnectors(true);
checkAllConnector(fccp, collector, allConnectors);
allConnectors = fccp.getAllSchemaPropertiesConnectors(false);
checkAllConnector(fccp, collector, allConnectors);
}
public static Properties checkSerialize(Properties props, ErrorCollector errorCollector) {
return PropertiesTestUtils.checkSerialize(props, errorCollector);
}
static public void checkAllI18N(Properties checkedProps, ErrorCollector errorCollector) {
PropertiesTestUtils.checkAllI18N(checkedProps, errorCollector);
}