List of usage examples for java.lang Error getCause
public synchronized Throwable getCause()
From source file:io.servicecomb.serviceregistry.config.TestPropertiesLoader.java
@Test public void testExtendedClassCompatible() { Configuration configuration = new DynamicConfiguration(); configuration.setProperty(CONFIG_SERVICE_DESCRIPTION_KEY + AbstractPropertiesLoader.EXTENDED_CLASS, "invalidClass"); AbstractPropertiesLoader loader = MicroservicePropertiesLoader.INSTANCE; try {/*from w w w .ja v a 2s. c o m*/ loader.loadProperties(configuration); Assert.fail("Must throw exception"); } catch (Error e) { Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass()); Assert.assertEquals("invalidClass", e.getCause().getMessage()); } }
From source file:io.servicecomb.serviceregistry.config.TestPropertiesLoader.java
@Test public void testInvalidExtendedClass() { ConfigModel configModel = MicroserviceDefinition.createConfigModel("default", "invalidExtendedClass"); @SuppressWarnings("unchecked") Map<String, Object> desc = (Map<String, Object>) configModel.getConfig() .get(CONFIG_SERVICE_DESCRIPTION_KEY); desc.put("propertyExtentedClass", "invalidClass"); MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Arrays.asList(configModel)); try {/* w w w . j av a 2s . co m*/ microserviceFactory.create(microserviceDefinition); Assert.fail("Must throw exception"); } catch (Error e) { Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass()); Assert.assertEquals("invalidClass", e.getCause().getMessage()); } }
From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java
@Test public void testCatchErrorInProcessFilesMethod() throws Exception { // The idea of the test is to satisfy coverage rate. // An Error indicates serious problems that a reasonable application should not try to // catch, but due to issue https://github.com/checkstyle/checkstyle/issues/2285 // we catch errors in 'processFiles' method. Most such errors are abnormal conditions, // that is why we use PowerMockito to reproduse them. final File mock = PowerMockito.mock(File.class); // Assume that I/O error is happened when we try to invoke 'lastModified()' method. final String errorMessage = "Java Virtual Machine is broken" + " or has run out of resources necessary for it to continue operating."; final Error expectedError = new IOError(new InternalError(errorMessage)); when(mock.lastModified()).thenThrow(expectedError); final Checker checker = new Checker(); final List<File> filesToProcess = Lists.newArrayList(); filesToProcess.add(mock);/*w w w . j a va2 s .c o m*/ try { checker.process(filesToProcess); fail("IOError is expected!"); } catch (Error error) { assertThat(error.getCause(), instanceOf(IOError.class)); assertThat(error.getCause().getCause(), instanceOf(InternalError.class)); assertEquals(errorMessage, error.getCause().getCause().getMessage()); } }