-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from gayanW/java-10_81
Move/Refactor ReflectionTest -> StackWalkerTest
- Loading branch information
Showing
2 changed files
with
71 additions
and
65 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/tests/gov/nasa/jpf/test/java/lang/StackWalkerTest.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,71 @@ | ||
/* | ||
* Copyright (C) 2014, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* All rights reserved. | ||
* | ||
* The Java Pathfinder core (jpf-core) platform is licensed under the | ||
* Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package gov.nasa.jpf.test.java.lang; | ||
|
||
import gov.nasa.jpf.util.test.TestJPF; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class StackWalkerTest extends TestJPF { | ||
|
||
static class MyClass { | ||
void bar(){ | ||
foo(); | ||
} | ||
|
||
/** | ||
* Traverse from the top frame of the stack which is the {@code foo} method | ||
* and assert that the declaring class of each stack frame is valid. | ||
* Reflection frames are ignored, see: {@link java.lang.StackWalker.Option#SHOW_REFLECT_FRAMES} | ||
*/ | ||
void foo (){ | ||
final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); | ||
List<Class<?>> callerClasses = walker.walk(s -> s | ||
.limit(4) | ||
.map(StackWalker.StackFrame::getDeclaringClass) | ||
.collect(Collectors.toList())); | ||
|
||
Class<?> callerCls = callerClasses.get(0); // foo() | ||
System.out.println("-- declaring class of the top frame of the stack = " + callerCls); | ||
assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.java.lang.StackWalkerTest$MyClass")); | ||
|
||
callerCls = callerClasses.get(1); // bar() | ||
System.out.println("-- StackFrame[1].getDeclaringClass = " + callerCls); | ||
assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.java.lang.StackWalkerTest$MyClass")); | ||
|
||
callerCls = callerClasses.get(2); // callIt() | ||
System.out.println("-- StackFrame[2].getDeclaringClass = " + callerCls); | ||
assertTrue(callerCls.getName().equals("gov.nasa.jpf.test.java.lang.StackWalkerTest")); | ||
} | ||
} | ||
|
||
void callIt(){ | ||
MyClass o = new MyClass(); | ||
o.bar(); | ||
} | ||
|
||
@Test | ||
public void testCallerClass() { | ||
if (verifyNoPropertyViolation()){ | ||
callIt(); | ||
} | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
src/tests/gov/nasa/jpf/test/vm/reflection/ReflectionTest.java
This file was deleted.
Oops, something went wrong.