Skip to content

Commit d0eebee

Browse files
nettozahlerjukzi
authored andcommitted
Test for #518 (Setting a breakpoint inside lambda with object).
1 parent 943dba1 commit d0eebee

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Christian Schima - initial API and implementation
13+
*******************************************************************************/
14+
import java.util.Optional;
15+
import java.util.function.Consumer;
16+
import java.util.function.Supplier;
17+
18+
/**
19+
* Test class with lambdas.
20+
*/
21+
public class ClassWithLambdas {
22+
23+
private static class Factory {
24+
public static <T> Factory create(Supplier<T> supplier, Consumer<T> consumer) {
25+
return new Factory();
26+
}
27+
}
28+
29+
public ClassWithLambdas(String parent) {
30+
Factory.create(() -> Optional.of(""), sample -> new Consumer<Optional<String>>() {
31+
32+
Optional<String> lastSample = Optional.empty();
33+
34+
@Override
35+
public void accept(Optional<String> currentSample) {
36+
lastSample.ifPresent(System.out::println);
37+
currentSample.ifPresent(System.out::println);
38+
lastSample = currentSample;
39+
}
40+
});
41+
}
42+
}

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/TestToggleBreakpointsTarget8.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@
2525
*/
2626
public class TestToggleBreakpointsTarget8 extends AbstractToggleBreakpointsTarget {
2727

28-
29-
30-
3128
public TestToggleBreakpointsTarget8(String name) {
3229
super(name);
33-
// TODO Auto-generated constructor stub
3430
}
3531

3632
/**
@@ -124,4 +120,26 @@ public void testInterfaceLineBreakpoint() throws Exception {
124120
}
125121
}
126122

123+
/**
124+
* Tests that a line breakpoints in an lambda expression works.
125+
*/
126+
public void testLineBreakpointInsideLambda() throws Exception {
127+
Listener listener = new Listener();
128+
IBreakpointManager manager = getBreakpointManager();
129+
manager.addBreakpointListener(listener);
130+
try {
131+
Path path = new Path("java8/ClassWithLambdas.java");
132+
final int lineNr = 35; // 0 based offset in document line numbers
133+
toggleBreakpoint(path, lineNr);
134+
TestUtil.waitForJobs(getName(), 100, DEFAULT_TIMEOUT);
135+
IBreakpoint added = listener.getAdded();
136+
assertTrue("Should be a line breakpoint", added instanceof IJavaLineBreakpoint);
137+
IJavaLineBreakpoint breakpoint = (IJavaLineBreakpoint) added;
138+
assertEquals("Wrong line number", lineNr + 1, breakpoint.getLineNumber());
139+
assertEquals("Wrong type name", "ClassWithLambdas", breakpoint.getTypeName());
140+
} finally {
141+
manager.removeBreakpointListener(listener);
142+
removeAllBreakpoints();
143+
}
144+
}
127145
}

0 commit comments

Comments
 (0)