Search in sources :

Example 1 with CheckstyleVersionMixException

use of org.infernus.idea.checkstyle.exception.CheckstyleVersionMixException in project checkstyle-idea by jshiell.

the class VersionMixExceptionTest method testVersionMixException.

/**
 * Test that a {@link CheckstyleVersionMixException} is thrown when a
 * {@link org.infernus.idea.checkstyle.csapi.CheckstyleInternalObject CheckstyleInternalObject} outlives its class
 * loader.
 */
public void testVersionMixException() throws IOException, URISyntaxException {
    Module module = mock(Module.class);
    when(module.getProject()).thenReturn(project);
    final CheckStyleChecker checker = createChecker(module);
    runChecker(checker);
    try {
        assertNotEquals(OTHER_VERSION, BASE_VERSION);
        // changes class loader, cause of error
        csService.activateCheckstyleVersion(OTHER_VERSION, null);
        runChecker(checker);
        fail("expected exception was not thrown");
    } catch (CheckstyleVersionMixException e) {
        // expected
        final String internalClassName = "org.infernus.idea.checkstyle.service.entities.CheckerWithConfig";
        assertTrue(e.getMessage().contains("Expected: " + internalClassName + ", actual: " + internalClassName));
    // Yes! Error, even though both class names are identical (but class loaders differ).
    } finally {
        csService.activateCheckstyleVersion(BASE_VERSION, null);
    }
}
Also used : CheckStyleChecker(org.infernus.idea.checkstyle.checker.CheckStyleChecker) CheckstyleVersionMixException(org.infernus.idea.checkstyle.exception.CheckstyleVersionMixException) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1 CheckStyleChecker (org.infernus.idea.checkstyle.checker.CheckStyleChecker)1 CheckstyleVersionMixException (org.infernus.idea.checkstyle.exception.CheckstyleVersionMixException)1