Skip to content

Commit

Permalink
Add lambda creation test case
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal authored and iloveeclipse committed Sep 1, 2017
1 parent b5c5cb1 commit 1708c26
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package edu.umd.cs.findbugs.detect;

import edu.umd.cs.findbugs.BugCollection;
import edu.umd.cs.findbugs.SortedBugCollection;
import edu.umd.cs.findbugs.test.SpotBugsRule;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;

import java.nio.file.Paths;

import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.collection.IsEmptyIterable.emptyIterable;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class ResolveMethodReferencesTest {
@Rule
public SpotBugsRule spotbugs = new SpotBugsRule();

/**
* @see <a href="https://github.com/spotbugs/spotbugs/issues/338">GitHub
* issue</a>
*/
@Test
public void testIssue338() {
BugCollection bugCollection = spotbugs.performAnalysis(Paths.get("../spotbugsTestCases/build/classes/java/main/lambdas/Issue338.class"));
assertThat(bugCollection, is(emptyIterable()));
assertThat(bugCollection, instanceOf(SortedBugCollection.class));
assertThat(((SortedBugCollection) bugCollection).missingClassIterator().hasNext(), is(false));
}
}
17 changes: 17 additions & 0 deletions spotbugsTestCases/src/java/lambdas/Issue338.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lambdas;

public class Issue338 {

public static void main(String[] args) {
Runnable a = System.err::println;
Runnable b = () -> {
if (System.getenv("SOME_RANDOM_VAR") == null) {
a.run();
}
a.run();
};
a.run();
b.run();
}

}

0 comments on commit 1708c26

Please sign in to comment.