Merge pull request #9452 from Maiklins/JAVA-1522-split-core-java-modules-core-java
Java-1522 split core java modules core java
This commit is contained in:
@@ -8,3 +8,5 @@
|
||||
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
||||
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
|
||||
- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
|
||||
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
||||
- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.java.currentmethod;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* The class presents various ways of finding the name of currently executed method.
|
||||
*/
|
||||
public class CurrentlyExecutedMethodFinderUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenCurrentThread_whenGetStackTrace_thenFindMethod() {
|
||||
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||
assertEquals("givenCurrentThread_whenGetStackTrace_thenFindMethod", stackTrace[1].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenException_whenGetStackTrace_thenFindMethod() {
|
||||
String methodName = new Exception().getStackTrace()[0].getMethodName();
|
||||
assertEquals("givenException_whenGetStackTrace_thenFindMethod", methodName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenThrowable_whenGetStacktrace_thenFindMethod() {
|
||||
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
|
||||
assertEquals("givenThrowable_whenGetStacktrace_thenFindMethod", stackTrace[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenGetEnclosingMethod_thenFindMethod() {
|
||||
String methodName = new Object() {}.getClass().getEnclosingMethod().getName();
|
||||
assertEquals("givenObject_whenGetEnclosingMethod_thenFindMethod", methodName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLocal_whenGetEnclosingMethod_thenFindMethod() {
|
||||
class Local {};
|
||||
String methodName = Local.class.getEnclosingMethod().getName();
|
||||
assertEquals("givenLocal_whenGetEnclosingMethod_thenFindMethod", methodName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user