|
|
@@ -1,124 +1,150 @@
|
|
|
-/*
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- * @copyright Ranides Atterwim
|
|
|
- * @license WTFPL
|
|
|
- * @url http://ranides.net/projects/assira
|
|
|
- */
|
|
|
-package net.ranides.assira.trace;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-import org.junit.Assert;
|
|
|
-import org.junit.Test;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- */
|
|
|
-public class StackInspectorTest {
|
|
|
-
|
|
|
- private static final Class<?> CALLER = StackInspectorTest.class;
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testCallerClass() {
|
|
|
- Class callerAuto = StackInspector.getCaller();
|
|
|
- Class callerSM = StackInspector.test_getCallerClass(StackInspector.RESOLVER_SM);
|
|
|
- Class callerSR = StackInspector.test_getCallerClass(StackInspector.RESOLVER_SR);
|
|
|
-
|
|
|
- Assert.assertEquals(CALLER, callerAuto);
|
|
|
- Assert.assertEquals(CALLER, callerSM);
|
|
|
- Assert.assertEquals(CALLER, callerSR);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testCallerClassName() {
|
|
|
- String callerAuto = StackInspector.getCallerName();
|
|
|
- String callerSM = StackInspector.test_getCallerClassName(StackInspector.RESOLVER_SM);
|
|
|
- String callerSR = StackInspector.test_getCallerClassName(StackInspector.RESOLVER_SR);
|
|
|
- String callerTS = StackInspector.test_getCallerClassName(StackInspector.RESOLVER_TS);
|
|
|
- String callerES = StackInspector.test_getCallerClassName(StackInspector.RESOLVER_ES);
|
|
|
-
|
|
|
- Assert.assertEquals(CALLER.getName(), callerAuto);
|
|
|
- Assert.assertEquals(CALLER.getName(), callerSM);
|
|
|
- Assert.assertEquals(CALLER.getName(), callerSR);
|
|
|
- Assert.assertEquals(CALLER.getName(), callerTS);
|
|
|
- Assert.assertEquals(CALLER.getName(), callerES);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testClassList() {
|
|
|
- List<Class> listAuto = StackInspector.getCallers();
|
|
|
- List<Class> listSM = StackInspector.test_getClassList(StackInspector.RESOLVER_SM);
|
|
|
- List<Class> listSR = StackInspector.test_getClassList(StackInspector.RESOLVER_SR);
|
|
|
-
|
|
|
- if(false) { //NOPMD
|
|
|
- dump(listAuto);
|
|
|
- dump(listSM);
|
|
|
- dump(listSR);
|
|
|
- }
|
|
|
-
|
|
|
- Assert.assertTrue(
|
|
|
- listAuto.equals(listSM) ||
|
|
|
- listAuto.equals(listSR)
|
|
|
- );
|
|
|
-
|
|
|
- Assert.assertEquals(listSM, listSR);
|
|
|
-
|
|
|
- Assert.assertTrue(listSM.size() > 5);
|
|
|
-
|
|
|
- Assert.assertEquals(CALLER, listSM.get(0));
|
|
|
- Assert.assertEquals(CALLER, listSR.get(0));
|
|
|
-
|
|
|
- Assert.assertFalse(CALLER.equals(listSM.get(1)));
|
|
|
- Assert.assertFalse(CALLER.equals(listSR.get(1)));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void testClassNames() {
|
|
|
- List<String> listAuto = StackInspector.getCallerNames();
|
|
|
- List<String> listSM = StackInspector.test_getClassNames(StackInspector.RESOLVER_SM);
|
|
|
- List<String> listSR = StackInspector.test_getClassNames(StackInspector.RESOLVER_SR);
|
|
|
- List<String> listTS = StackInspector.test_getClassNames(StackInspector.RESOLVER_TS);
|
|
|
- List<String> listES = StackInspector.test_getClassNames(StackInspector.RESOLVER_ES);
|
|
|
-
|
|
|
- if(false) { //NOPMD
|
|
|
- dump(listAuto);
|
|
|
- dump(listSM);
|
|
|
- dump(listSR);
|
|
|
- dump(listTS);
|
|
|
- dump(listES);
|
|
|
- }
|
|
|
-
|
|
|
- Assert.assertTrue(
|
|
|
- listAuto.equals(listSM) ||
|
|
|
- listAuto.equals(listSR) ||
|
|
|
- listAuto.equals(listTS) ||
|
|
|
- listAuto.equals(listES)
|
|
|
- );
|
|
|
-
|
|
|
- Assert.assertEquals(listSM, listSR);
|
|
|
- Assert.assertEquals(listTS, listES);
|
|
|
-
|
|
|
- Assert.assertTrue(listSM.size() > 5);
|
|
|
- Assert.assertTrue(listSM.size() <= listTS.size());
|
|
|
-
|
|
|
- Assert.assertEquals(CALLER.getName(), listSM.get(0));
|
|
|
- Assert.assertEquals(CALLER.getName(), listSR.get(0));
|
|
|
- Assert.assertEquals(CALLER.getName(), listTS.get(0));
|
|
|
- Assert.assertEquals(CALLER.getName(), listES.get(0));
|
|
|
-
|
|
|
- Assert.assertFalse(CALLER.getName().equals(listSM.get(1)));
|
|
|
- Assert.assertFalse(CALLER.getName().equals(listSR.get(1)));
|
|
|
- Assert.assertFalse(CALLER.getName().equals(listTS.get(1)));
|
|
|
- Assert.assertFalse(CALLER.getName().equals(listES.get(1)));
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressWarnings("PMD")
|
|
|
- private static void dump(List<?> list) {
|
|
|
- int i = 0;
|
|
|
- for(Object c : list) {
|
|
|
- System.err.printf("%d. %s%n", i++, c);
|
|
|
- }
|
|
|
- System.out.printf("%n");
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+/*
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ * @copyright Ranides Atterwim
|
|
|
+ * @license WTFPL
|
|
|
+ * @url http://ranides.net/projects/assira
|
|
|
+ */
|
|
|
+package net.ranides.assira.trace;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import static org.junit.Assert.*;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ */
|
|
|
+public class StackInspectorTest {
|
|
|
+
|
|
|
+ private static final Class<?> CALLER = StackInspectorTest.class;
|
|
|
+
|
|
|
+ private static StackTraceElement innerFrame(int index) {
|
|
|
+ return StackInspector.getFrames().get(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<StackTraceElement> innerFrames() {
|
|
|
+ return StackInspector.getFrames();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCallerClass() {
|
|
|
+ Class callerAuto = StackInspector.getCalleeType();
|
|
|
+ Class callerSM = StackInspector.test_getCalleeClass(StackInspector.RESOLVER_SM);
|
|
|
+ Class callerSR = StackInspector.test_getCalleeClass(StackInspector.RESOLVER_SR);
|
|
|
+
|
|
|
+ assertEquals(CALLER, callerAuto);
|
|
|
+ assertEquals(CALLER, callerSM);
|
|
|
+ assertEquals(CALLER, callerSR);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testCallerClassName() {
|
|
|
+ String callerAuto = StackInspector.getCalleeName();
|
|
|
+ String callerSM = StackInspector.test_getCalleeName(StackInspector.RESOLVER_SM);
|
|
|
+ String callerSR = StackInspector.test_getCalleeName(StackInspector.RESOLVER_SR);
|
|
|
+ String callerTS = StackInspector.test_getCalleeName(StackInspector.RESOLVER_TS);
|
|
|
+ String callerES = StackInspector.test_getCalleeName(StackInspector.RESOLVER_ES);
|
|
|
+
|
|
|
+ assertEquals(CALLER.getName(), callerAuto);
|
|
|
+ assertEquals(CALLER.getName(), callerSM);
|
|
|
+ assertEquals(CALLER.getName(), callerSR);
|
|
|
+ assertEquals(CALLER.getName(), callerTS);
|
|
|
+ assertEquals(CALLER.getName(), callerES);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testClassList() {
|
|
|
+ List<Class> listAuto = StackInspector.getTypes();
|
|
|
+ List<Class> listSM = StackInspector.test_getClassList(StackInspector.RESOLVER_SM);
|
|
|
+ List<Class> listSR = StackInspector.test_getClassList(StackInspector.RESOLVER_SR);
|
|
|
+
|
|
|
+ if(false) { //NOPMD
|
|
|
+ dump(listAuto);
|
|
|
+ dump(listSM);
|
|
|
+ dump(listSR);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertTrue(
|
|
|
+ listAuto.equals(listSM) ||
|
|
|
+ listAuto.equals(listSR)
|
|
|
+ );
|
|
|
+
|
|
|
+ assertEquals(listSM, listSR);
|
|
|
+
|
|
|
+ assertTrue(listSM.size() > 5);
|
|
|
+
|
|
|
+ assertEquals(CALLER, listSM.get(0));
|
|
|
+ assertEquals(CALLER, listSR.get(0));
|
|
|
+
|
|
|
+ assertFalse(CALLER.equals(listSM.get(1)));
|
|
|
+ assertFalse(CALLER.equals(listSR.get(1)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testClassNames() {
|
|
|
+ List<String> listAuto = StackInspector.getNames();
|
|
|
+ List<String> listSM = StackInspector.test_getClassNames(StackInspector.RESOLVER_SM);
|
|
|
+ List<String> listSR = StackInspector.test_getClassNames(StackInspector.RESOLVER_SR);
|
|
|
+ List<String> listTS = StackInspector.test_getClassNames(StackInspector.RESOLVER_TS);
|
|
|
+ List<String> listES = StackInspector.test_getClassNames(StackInspector.RESOLVER_ES);
|
|
|
+
|
|
|
+ if(false) { //NOPMD
|
|
|
+ dump(listAuto);
|
|
|
+ dump(listSM);
|
|
|
+ dump(listSR);
|
|
|
+ dump(listTS);
|
|
|
+ dump(listES);
|
|
|
+ }
|
|
|
+
|
|
|
+ assertTrue(
|
|
|
+ listAuto.equals(listSM) ||
|
|
|
+ listAuto.equals(listSR) ||
|
|
|
+ listAuto.equals(listTS) ||
|
|
|
+ listAuto.equals(listES)
|
|
|
+ );
|
|
|
+
|
|
|
+ assertEquals(listSM, listSR);
|
|
|
+ assertEquals(listTS, listES);
|
|
|
+
|
|
|
+ assertTrue(listSM.size() > 5);
|
|
|
+ assertTrue(listSM.size() <= listTS.size());
|
|
|
+
|
|
|
+ assertEquals(CALLER.getName(), listSM.get(0));
|
|
|
+ assertEquals(CALLER.getName(), listSR.get(0));
|
|
|
+ assertEquals(CALLER.getName(), listTS.get(0));
|
|
|
+ assertEquals(CALLER.getName(), listES.get(0));
|
|
|
+
|
|
|
+ assertFalse(CALLER.getName().equals(listSM.get(1)));
|
|
|
+ assertFalse(CALLER.getName().equals(listSR.get(1)));
|
|
|
+ assertFalse(CALLER.getName().equals(listTS.get(1)));
|
|
|
+ assertFalse(CALLER.getName().equals(listES.get(1)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFrame() {
|
|
|
+ String t1 = "net.ranides.assira.trace.StackInspectorTest.innerFrame(StackInspectorTest.java:22)";
|
|
|
+ String t2 = "net.ranides.assira.trace.StackInspectorTest.testFrame(StackInspectorTest.java:128)";
|
|
|
+ assertEquals(t1, innerFrame(0).toString());
|
|
|
+ assertEquals(t2, innerFrame(1).toString());
|
|
|
+ assertFalse(innerFrame(2).toString().startsWith("net.ranides"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFrames() {
|
|
|
+ String t1 = "net.ranides.assira.trace.StackInspectorTest.innerFrames(StackInspectorTest.java:26)";
|
|
|
+ String t2 = "net.ranides.assira.trace.StackInspectorTest.testFrames(StackInspectorTest.java:137)";
|
|
|
+ assertEquals(t1, innerFrames().get(0).toString());
|
|
|
+ assertEquals(t2, innerFrames().get(1).toString());
|
|
|
+ assertFalse(innerFrames().get(2).toString().startsWith("net.ranides"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("PMD")
|
|
|
+ private static void dump(List<?> list) {
|
|
|
+ int i = 0;
|
|
|
+ for(Object c : list) {
|
|
|
+ System.err.printf("%d. %s%n", i++, c);
|
|
|
+ }
|
|
|
+ System.out.printf("%n");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|