-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
260 additions
and
70 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/GroupedStackFrameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Zsombor Gegesy. | ||
* | ||
* 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: | ||
* Zsombor Gegesy - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.debug.tests.ui; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertSame; | ||
|
||
import org.eclipse.jdt.debug.core.IJavaStackFrame; | ||
import org.eclipse.jdt.internal.debug.core.model.GroupedStackFrame; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class GroupedStackFrameTest { | ||
|
||
private GroupedStackFrame groupedStackFrame; | ||
|
||
private IJavaStackFrame mockFrame1; | ||
private IJavaStackFrame mockFrame2; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
groupedStackFrame = new GroupedStackFrame(null); | ||
mockFrame1 = JavaStackFrameMock.createFrame(JavaReferenceTypeMock.createReference("java.util.ArrayList"), false); | ||
mockFrame2 = JavaStackFrameMock.createFrame(JavaReferenceTypeMock.createReference("java.util.LinkedList"), false); | ||
} | ||
|
||
@Test | ||
public void testAddFrame() { | ||
groupedStackFrame.add(mockFrame1); | ||
assertEquals(1, groupedStackFrame.getFrameCount()); | ||
|
||
groupedStackFrame.add(mockFrame2); | ||
assertEquals(2, groupedStackFrame.getFrameCount()); | ||
} | ||
|
||
@Test | ||
public void testGetFrameCount() { | ||
assertEquals(0, groupedStackFrame.getFrameCount()); | ||
|
||
groupedStackFrame.add(mockFrame1); | ||
assertEquals(1, groupedStackFrame.getFrameCount()); | ||
|
||
groupedStackFrame.add(mockFrame2); | ||
assertEquals(2, groupedStackFrame.getFrameCount()); | ||
} | ||
|
||
@Test | ||
public void testGetFramesAsArray() { | ||
groupedStackFrame.add(mockFrame1); | ||
groupedStackFrame.add(mockFrame2); | ||
|
||
Object[] frames = groupedStackFrame.getFramesAsArray(0, 2); | ||
assertNotNull(frames); | ||
assertEquals(2, frames.length); | ||
assertSame(mockFrame1, frames[0]); | ||
assertSame(mockFrame2, frames[1]); | ||
|
||
frames = groupedStackFrame.getFramesAsArray(1, 1); | ||
assertNotNull(frames); | ||
assertEquals(1, frames.length); | ||
assertSame(mockFrame2, frames[0]); | ||
|
||
frames = groupedStackFrame.getFramesAsArray(2, 1); | ||
assertNull(frames); | ||
} | ||
|
||
@Test | ||
public void testGetTopMostFrame() { | ||
assertNull(groupedStackFrame.getTopMostFrame()); | ||
|
||
groupedStackFrame.add(mockFrame1); | ||
assertSame(mockFrame1, groupedStackFrame.getTopMostFrame()); | ||
|
||
groupedStackFrame.add(mockFrame2); | ||
assertSame(mockFrame1, groupedStackFrame.getTopMostFrame()); | ||
} | ||
|
||
@Test | ||
public void testGetAdapter() { | ||
var adapterType = String.class; | ||
|
||
groupedStackFrame.add(mockFrame1); | ||
Object adapter = groupedStackFrame.getAdapter(adapterType); | ||
assertEquals("getAdapter called with class java.lang.String", adapter); | ||
|
||
groupedStackFrame = new GroupedStackFrame(null); | ||
adapter = groupedStackFrame.getAdapter(adapterType); | ||
assertNull(adapter); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/JavaReferenceTypeMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Zsombor Gegesy. | ||
* | ||
* 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: | ||
* Zsombor Gegesy - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.debug.tests.ui; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
import org.eclipse.jdt.debug.core.IJavaReferenceType; | ||
|
||
/** | ||
* Class to mock {@link IJavaReferenceType}. | ||
*/ | ||
class JavaReferenceTypeMock implements InvocationHandler { | ||
|
||
final String name; | ||
|
||
JavaReferenceTypeMock(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
if ("getName".equals(method.getName())) { | ||
return name; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Create a new mocked {@link IJavaReferenceType}. | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
public static IJavaReferenceType createReference(String name) { | ||
return (IJavaReferenceType) Proxy.newProxyInstance(JavaReferenceTypeMock.class.getClassLoader(), new Class[] { | ||
IJavaReferenceType.class }, new JavaReferenceTypeMock(name)); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/JavaStackFrameMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Zsombor Gegesy. | ||
* | ||
* 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: | ||
* Zsombor Gegesy - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.debug.tests.ui; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
import org.eclipse.jdt.debug.core.IJavaReferenceType; | ||
import org.eclipse.jdt.debug.core.IJavaStackFrame; | ||
|
||
class JavaStackFrameMock implements InvocationHandler { | ||
|
||
final IJavaReferenceType referenceType; | ||
final boolean synthetic; | ||
|
||
JavaStackFrameMock(IJavaReferenceType referenceType, boolean synthetic) { | ||
this.referenceType = referenceType; | ||
this.synthetic = synthetic; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
var methodName = method.getName(); | ||
if ("getReferenceType".equals(methodName)) { | ||
return referenceType; | ||
} | ||
if ("isSynthetic".equals(methodName)) { | ||
return synthetic; | ||
} | ||
if ("getLaunch".equals(methodName)) { | ||
return LaunchMock.createLaunch(); | ||
} | ||
if ("getAdapter".equals(methodName)) { | ||
return "getAdapter called with " + args[0]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Create a mocked {@link IJavaStackFrame} | ||
* | ||
* @param refType | ||
* the type in which this stack frame's method is declared | ||
* @param syntetic | ||
* if the frame is synthetic or not. | ||
* @return a mocked stack frame. | ||
*/ | ||
public static IJavaStackFrame createFrame(IJavaReferenceType refType, boolean syntetic) { | ||
return (IJavaStackFrame) Proxy.newProxyInstance(JavaStackFrameMock.class.getClassLoader(), new Class[] { | ||
IJavaStackFrame.class }, new JavaStackFrameMock(refType, syntetic)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/ui/LaunchMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Zsombor Gegesy. | ||
* | ||
* 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: | ||
* Zsombor Gegesy - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.debug.tests.ui; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
import org.eclipse.debug.core.ILaunch; | ||
|
||
/** | ||
* Class to mock {@link ILaunch}. | ||
*/ | ||
class LaunchMock implements InvocationHandler { | ||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
return null; | ||
} | ||
|
||
public static ILaunch createLaunch() { | ||
return (ILaunch) Proxy.newProxyInstance(LaunchMock.class.getClassLoader(), new Class[] { ILaunch.class }, new LaunchMock()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters