Skip to content

Commit

Permalink
Test for #518 (Setting a breakpoint inside lambda with object).
Browse files Browse the repository at this point in the history
  • Loading branch information
nettozahler committed Nov 14, 2024
1 parent 8133adf commit a309be9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
42 changes: 42 additions & 0 deletions org.eclipse.jdt.debug.tests/java8/ClassWithLambdas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christian Schima - initial API and implementation
*******************************************************************************/
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* Test class with lambdas.
*/
public class ClassWithLambdas {

private static class Factory {
public static <T> Factory create(Supplier<T> supplier, Consumer<T> consumer) {
return new Factory();
}
}

public ClassWithLambdas(String parent) {
Factory.create(() -> Optional.of(""), sample -> new Consumer<Optional<String>>() {

Optional<String> lastSample = Optional.empty();

@Override
public void accept(Optional<String> currentSample) {
lastSample.ifPresent(System.out::println);
currentSample.ifPresent(System.out::println);
lastSample = currentSample;
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
*/
public class TestToggleBreakpointsTarget8 extends AbstractToggleBreakpointsTarget {




public TestToggleBreakpointsTarget8(String name) {
super(name);
// TODO Auto-generated constructor stub
}

/**
Expand Down Expand Up @@ -124,4 +120,26 @@ public void testInterfaceLineBreakpoint() throws Exception {
}
}

/**
* Tests that a line breakpoints in an lambda expression works.
*/
public void testLineBreakpointInsideLambda() throws Exception {
Listener listener = new Listener();
IBreakpointManager manager = getBreakpointManager();
manager.addBreakpointListener(listener);
try {
Path path = new Path("java8/ClassWithLambdas.java");
final int lineNr = 35; // 0 based offset in document line numbers
toggleBreakpoint(path, lineNr);
TestUtil.waitForJobs(getName(), 100, DEFAULT_TIMEOUT);
IBreakpoint added = listener.getAdded();
assertTrue("Should be a line breakpoint", added instanceof IJavaLineBreakpoint);
IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) added;
assertEquals("Wrong line number", lineNr + 1, breakpoint.getLineNumber());
assertEquals("Wrong type name", "ClassWithLambdas", breakpoint.getTypeName());
} finally {
manager.removeBreakpointListener(listener);
removeAllBreakpoints();
}
}
}

0 comments on commit a309be9

Please sign in to comment.