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 * @since 0.18
14 */
15 final class UnusedImportsRuleTest {
16
17 /**
18 * UnusedImport can detect when the class has an unused import line and
19 * show error message correctly.
20 * @throws Exception If something goes wrong
21 */
22 @Test
23 void detectUnusedImportLine() throws Exception {
24 new PmdAssert(
25 "UnusedImports.java",
26 new IsEqual<>(false),
27 new StringStartsWith(
28 String.join(
29 " ",
30 "PMD: UnusedImports.java[7-7]: Unused import",
31 "'unused.bar.foo.UnusedImport'",
32 "(UnnecessaryImport)"
33 ).trim()
34 )
35 ).assertOk();
36 }
37 }