Skip to content

Commit

Permalink
Test added
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKnoll committed Nov 28, 2023
1 parent 95f1754 commit d51ecda
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ void testConstructorThrowCheck16() {
assertCTBugInLine(10);
}

@Test
void testConstructorThrowCheck18() {
performAnalysis("constructorthrow/ConstructorThrowTest18.class");
assertNumOfCTBugs(1);
assertCTBugInLine(13);
}

@Test
void testConstructorThrowCheck19() {
performAnalysis("constructorthrow/ConstructorThrowTest19.class");
assertNumOfCTBugs(1);
assertCTBugInLine(14);
}

@Test
void testGoodConstructorThrowCheck1() {
performAnalysis("constructorthrow/ConstructorThrowNegativeTest1.class");
Expand Down Expand Up @@ -203,6 +217,12 @@ void testGoodConstructorThrowCheck13() {
assertNumOfCTBugs(0);
}

@Test
void testGoodConstructorThrowCheck16() {
performAnalysis("constructorthrow/ConstructorThrowNegativeTest16.class");
assertNumOfCTBugs(0);
}

private void assertNumOfCTBugs(int num) {
final BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder()
.bugType("CT_CONSTRUCTOR_THROW").build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package constructorthrow;

import java.util.function.Supplier;

/**
* The lambda which throws the exception is created and assigned to a field, but not used.
* @see <a href="https://github.com/spotbugs/spotbugs/issues/2695">GitHub issue #2695</a>
*/
public class ConstructorThrowNegativeTest16 {
Supplier<String> s;

public ConstructorThrowNegativeTest16() {
s = ConstructorThrowNegativeTest16::supplier;
}

private static String supplier() {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package constructorthrow;

/**
* The lambda which throws the exception is created and assigned to a field, and used in the Constructor.
* It's similar to {@link ConstructorThrowNegativeTest16}, but it throws an exception.
*/
public class ConstructorThrowTest18 {
String s;

public ConstructorThrowTest18() {
s = ConstructorThrowTest18.supplier();
}

private static String supplier() {
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package constructorthrow;

import java.util.function.Supplier;

/**
* The lambda which throws the exception is created and assigned to a field, and used in the Constructor.
* It's similar to {@link ConstructorThrowNegativeTest16}, but it throws an exception.
*/
public class ConstructorThrowTest19 {
Supplier<String> s;

public ConstructorThrowTest19() {
s = ConstructorThrowTest19::supplier;
String str = s.get();
}

private static String supplier() {
throw new IllegalStateException();
}
}

0 comments on commit d51ecda

Please sign in to comment.