Skip to content

Instantly share code, notes, and snippets.

@heruan
Last active February 27, 2024 18:41
Show Gist options
  • Save heruan/817705978ad33926147ad8780785af4b to your computer and use it in GitHub Desktop.
Save heruan/817705978ad33926147ad8780785af4b to your computer and use it in GitHub Desktop.
Minimal example triggering error on VS Code: Testing with coverage
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
class AnyTest {
@Test
void test() {
assertTrue(true);
}
}
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public class Sample {
void sample(boolean x) {
var foo = getFoo();
if (x) {
foo = new Foo(); // <-- BOTH THIS LINE
}
var bar = new Bar();
var baz = new Baz();
baz.from(bar::bar)
.as(Sample::toArray) // <-- AND THIS LINE
.to(foo::foo);
}
static String[] toArray(List<String> s) {
return s.toArray(String[]::new);
}
static Foo getFoo() {
return new Foo();
}
static class Foo {
void foo(String... foo) {
}
}
static class Bar {
List<String> bar() {
return List.of("bar");
}
}
static class Baz {
Baz from(Supplier<List<String>> from) {
return this;
}
Baz as(Function<List<String>, String[]> as) {
return this;
}
Baz to(Consumer<String[]> to) {
return this;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment