1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2011-2026 Yegor Bugayenko
3 * SPDX-License-Identifier: MIT
4 */
5 package com.qulice.pmd;
6
7 import org.hamcrest.core.IsEqual;
8 import org.hamcrest.core.StringStartsWith;
9 import org.junit.jupiter.api.Test;
10
11 /**
12 * Test case for LocalVariableCouldBeFinal.
13 *
14 * @since 0.18
15 */
16 final class UnusedImportsRuleTest {
17
18 /**
19 * UnusedImport can detect when the class has an unused import line and
20 * show error message correctly.
21 *
22 * @throws Exception If something goes wrong
23 */
24 @Test
25 void detectUnusedImportLine() throws Exception {
26 new PmdAssert(
27 "UnusedImports.java",
28 new IsEqual<>(false),
29 new StringStartsWith(
30 String.join(
31 " ",
32 "PMD: UnusedImports.java[7-7]: Unused import",
33 "'unused.bar.foo.UnusedImport'",
34 "(UnnecessaryImport)"
35 ).trim()
36 )
37 ).validate();
38 }
39 }