|
| 1 | +/* |
| 2 | + * Copyright (c) 2011-2018, Qulice.com |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: 1) Redistributions of source code must retain the above |
| 8 | + * copyright notice, this list of conditions and the following |
| 9 | + * disclaimer. 2) Redistributions in binary form must reproduce the above |
| 10 | + * copyright notice, this list of conditions and the following |
| 11 | + * disclaimer in the documentation and/or other materials provided |
| 12 | + * with the distribution. 3) Neither the name of the Qulice.com nor |
| 13 | + * the names of its contributors may be used to endorse or promote |
| 14 | + * products derived from this software without specific prior written |
| 15 | + * permission. |
| 16 | + * |
| 17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT |
| 19 | + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 21 | + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 22 | + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 28 | + * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | + */ |
| 30 | +package com.qulice.spotbugs; |
| 31 | + |
| 32 | +import com.qulice.spi.Environment; |
| 33 | +import org.junit.Ignore; |
| 34 | +import org.junit.Test; |
| 35 | + |
| 36 | +/** |
| 37 | + * Test case for {@link SpotBugsValidator}. |
| 38 | + * @since 0.19 |
| 39 | + * @todo #884:30min Continue migration from FindBugs to SpotBugs. Implement |
| 40 | + * SpotBugsValidator for this and then uncomment SpotBugsValidatorTest class |
| 41 | + * so the minimal tests on this class can be run. Then, after all is set, |
| 42 | + * remove FindBugs references from pom and from qulice executions. |
| 43 | + */ |
| 44 | +@SuppressWarnings("PMD.AvoidDuplicateLiterals") |
| 45 | +@Ignore |
| 46 | +public final class SpotBugsValidatorTest { |
| 47 | + |
| 48 | + /** |
| 49 | + * SpotBugsValidatorTest can pass correct files with no exceptions. |
| 50 | + * @throws Exception If something wrong happens inside |
| 51 | + */ |
| 52 | + @Test |
| 53 | + public void passesCorrectFilesWithNoExceptions() throws Exception { |
| 54 | + final Environment env = new Environment.Mock() |
| 55 | + .withFile("src/main/java/Main.java", "class Main { int x = 0; }") |
| 56 | + .withDefaultClasspath(); |
| 57 | + new SpotBugsValidator().validate(env); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * SpotBugs can exclude classes from check. |
| 62 | + * @throws Exception If something wrong happens inside |
| 63 | + */ |
| 64 | + @Test |
| 65 | + public void excludesIncorrectClassFormCheck() throws Exception { |
| 66 | + final Environment env = new Environment.Mock() |
| 67 | + .withFile( |
| 68 | + "target/classes/Foo.class", |
| 69 | + "class Foo { public Foo clone() { return this; } }" |
| 70 | + ).withExcludes("Foo").withDefaultClasspath(); |
| 71 | + new SpotBugsValidator().validate(env); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * FindbugsValidator can exclude several classes from check. |
| 76 | + * @throws Exception If something wrong happens inside |
| 77 | + */ |
| 78 | + @Test |
| 79 | + public void excludesSeveralIncorrectClassFromCheck() throws Exception { |
| 80 | + final Environment env = new Environment.Mock() |
| 81 | + .withFile( |
| 82 | + "target/classes/Foo.java", |
| 83 | + "class Foo { public Foo clone() { return this; } }" |
| 84 | + ).withFile( |
| 85 | + "target/classes/Bar.java", |
| 86 | + "class Bar { public Bar clone() { return this; } }" |
| 87 | + ).withExcludes("Foo,Bar") |
| 88 | + .withDefaultClasspath(); |
| 89 | + new SpotBugsValidator().validate(env); |
| 90 | + } |
| 91 | +} |
1 commit comments
0pdd commentedon Dec 5, 2018
Puzzle
884-ab2ca2fa
discovered inqulice-spotbugs/src/test/java/com.qulice.spotbugs/SpotBugsValidatorTest.java
and submitted as #959. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.