本文整理汇总了Java中org.yaml.snakeyaml.constructor.ConstructorException类的典型用法代码示例。如果您正苦于以下问题:Java ConstructorException类的具体用法?Java ConstructorException怎么用?Java ConstructorException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorException类属于org.yaml.snakeyaml.constructor包,在下文中一共展示了ConstructorException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getErrorMessage
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
public String getErrorMessage(Throwable e) {
String errorMessage = e.getMessage();
if (e instanceof ScannerException &&
(errorMessage.startsWith(MAPPING_VALUES_NOT_ALLOWED_HERE_ERROR) ||
errorMessage.startsWith(SCANNING_A_SIMPLE_KEY_ERROR))) {
errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
} else if (e instanceof ConstructorException && errorMessage.startsWith(CANNOT_CREATE_PROPERTY_ERROR)) {
if (errorMessage.contains(UNABLE_TO_FIND_PROPERTY_ERROR)) {
//parse for undefined property name
String truncatedErrorMessage = errorMessage.substring(errorMessage.indexOf(TRUNCATION_BEGINNING),
errorMessage.indexOf(TRUNCATION_END));
String undefinedProperty = truncatedErrorMessage.substring(truncatedErrorMessage.indexOf("\'") + 1,
truncatedErrorMessage.lastIndexOf("\'"));
errorMessage += "Property \'" + undefinedProperty + "\' is not supported by CloudSlang. Check that \'" +
undefinedProperty + "\' is indented properly.";
} else if (errorMessage.contains(MAP_CONSTRUCTOR_NOT_FOUND_ERROR)) {
errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
}
}
return errorMessage;
}
示例2: testStringCharArray
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
public void testStringCharArray() {
Yaml yaml = new Yaml();
try {
yaml.load(pkg + ".CharArr [ [ abcd ] ]");
fail("Expected exception.");
} catch (Exception e) {
assertEquals(ConstructorException.class, e.getClass());
assertEquals("Invalid node Character: 'abcd'; length: 4", e.getCause().getMessage());
}
}
示例3: testYamlThrowsConstructorExceptionShouldThrowIllegalArgumentException
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
@Test
public void testYamlThrowsConstructorExceptionShouldThrowIllegalArgumentException() {
Yaml mockYaml = mock(Yaml.class);
when(mockYaml.loadAs(anyString(), Matchers.<Class<Object>>anyObject())).thenThrow(ConstructorException.class);
reader.setYaml(mockYaml);
reader.read(User.class);
}
示例4: shouldThrowExceptionWhenCannotLoadSettings
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
@Test
public void shouldThrowExceptionWhenCannotLoadSettings() throws IOException {
shouldLoadWithError(FileNotFoundException.class);
FileUtils.writeStringToFile(settingsFile, "something weird");
shouldLoadWithError(ConstructorException.class);
settings.save();
settingsFile.setReadable(false);
shouldLoadWithError(FileNotFoundException.class);
}
示例5: testReadYamlFromResource_badResource
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
@Test(expected = ConstructorException.class)
public void testReadYamlFromResource_badResource() {
YamlUtils.readChatAlyticsConfig("config/bad-config.yaml");
}
示例6: readBadVersion
import org.yaml.snakeyaml.constructor.ConstructorException; //导入依赖的package包/类
@Test(expected = ConstructorException.class)
public void readBadVersion() throws ConfigurationException, UnsupportedEncodingException, IOException {
try (Reader in = new InputStreamReader(getClass().getResourceAsStream("/srcdeps-bad-version.yaml"), "utf-8")) {
new YamlConfigurationIo().read(in);
}
}