Skip to content

Commit e08a98a

Browse files
committed
Add test for when the maven checkstyle plugin is not configured but syncing is enabled
1 parent 4c67477 commit e08a98a

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

src/test/java/org/infernus/idea/checkstyle/maven/MavenCheckstyleConfiguratorTest.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.infernus.idea.checkstyle.model.ScanScope;
1818
import org.jetbrains.idea.maven.utils.MavenUtil;
1919
import org.junit.Test;
20-
import org.slf4j.Logger;
21-
import org.slf4j.LoggerFactory;
2220

2321
public class MavenCheckstyleConfiguratorTest extends MavenMultiVersionImportingTestCase {
2422

@@ -27,9 +25,7 @@ public class MavenCheckstyleConfiguratorTest extends MavenMultiVersionImportingT
2725
<artifactId>test</artifactId>
2826
<version>1</version>
2927
<name>test</name>
30-
""";
31-
private static final Logger log = LoggerFactory.getLogger(
32-
MavenCheckstyleConfiguratorTest.class);
28+
""".stripIndent();
3329

3430
@Test
3531
public void afterImport_importSettingsFromMavenIsDisabled_doesNothing() throws Exception {
@@ -318,8 +314,8 @@ public void updatePluginConfigLocationsFromMavenPlugin_configLocationExistsAndMa
318314
final var configurationLocationFactory = getProject().getService(
319315
ConfigurationLocationFactory.class);
320316

321-
final var configPath = Files.writeString(
322-
getProjectRoot().toNioPath().resolve("checkstyle.xml"), "<config></config>");
317+
final var configPath = Files.writeString(
318+
getProjectRoot().toNioPath().resolve("checkstyle.xml"), "<config></config>");
323319
final var mavenConfigLocation = configurationLocationFactory.create(getProject(),
324320
"maven-config-location", ConfigurationType.PROJECT_RELATIVE, "checkstyle-existing.xml",
325321
"Maven Config Location", NamedScopeHelper.getDefaultScope(getProject()));
@@ -361,8 +357,8 @@ public void updatePluginConfigLocationsFromMavenPlugin_mavenConfigDoesNotAlready
361357
final var pluginConfigurationManager = getProject().getService(
362358
PluginConfigurationManager.class);
363359

364-
final var configPath = Files.writeString(
365-
getProjectRoot().toNioPath().resolve("checkstyle.xml"), "<config></config>");
360+
final var configPath = Files.writeString(
361+
getProjectRoot().toNioPath().resolve("checkstyle.xml"), "<config></config>");
366362
final var updatedConfigurationBuilder = PluginConfigurationBuilder.from(
367363
pluginConfigurationManager.getCurrent());
368364
updatedConfigurationBuilder.withImportSettingsFromMaven(true).withLocations(new TreeSet<>())
@@ -457,4 +453,36 @@ public void updatePluginScanScopeFromMavenPlugin_includeSettingsExistsAndScanSco
457453

458454
assertEquals(ScanScope.JavaOnly, pluginConfigurationManager.getCurrent().getScanScope());
459455
}
456+
457+
@Test
458+
public void afterImport_mavenCheckstylePluginNotConfiguredAndSyncEnabled_doesNotThrow()
459+
throws Exception {
460+
final var pluginConfigurationManager = getProject().getService(
461+
PluginConfigurationManager.class);
462+
463+
final var updatedConfigurationBuilder = PluginConfigurationBuilder.from(
464+
pluginConfigurationManager.getCurrent());
465+
updatedConfigurationBuilder.withImportSettingsFromMaven(true);
466+
pluginConfigurationManager.setCurrent(updatedConfigurationBuilder.build(), true);
467+
468+
createProjectPom(PROJECT_INFO);
469+
470+
assertDoesNotThrow(() -> BuildersKt.runBlocking(EmptyCoroutineContext.INSTANCE,
471+
(scope, continuation) -> importProjectAsync(continuation)));
472+
}
473+
474+
// TODO: Replace this when migrating to JUnit 5.
475+
private void assertDoesNotThrow(Executable executable) {
476+
try {
477+
executable.execute();
478+
} catch (Exception e) {
479+
fail("Unexpected exception thrown: " + e.getClass().getName() + ": " + e.getMessage());
480+
}
481+
}
482+
483+
@FunctionalInterface
484+
interface Executable {
485+
486+
void execute() throws Exception;
487+
}
460488
}

0 commit comments

Comments
 (0)