### Question:
OpenmrsSecurityManager extends SecurityManager { public Class<?> getCallerClass(int callStackDepth) { if (callStackDepth < 0) { throw new APIException("call.stack.depth.error", (Object[]) null); } int skipClasses = 1; Class<?>[] classContext = getClassContext(); for (Class<?> clazz : classContext) { if (SecurityManager.class.isAssignableFrom(clazz)) { skipClasses++; } else { break; } } return getClassContext()[callStackDepth + skipClasses]; }  Class<?> getCallerClass(int callStackDepth);  }### Answer:
@Test public void getCallerClass_shouldGetTheMostRecentlyCalledMethod() { OpenmrsSecurityManager openmrsSecurityManager = new OpenmrsSecurityManager(); Class<?> callerClass = openmrsSecurityManager.getCallerClass(0); Assert.assertTrue("Oops, didn't get a junit type of class: " + callerClass, callerClass.getPackage().getName() .contains("junit")); }
@Test(expected = APIException.class) public void getCallerClass_shouldThrowAnErrorIfGivenASubzeroCallStackLevel() { new OpenmrsSecurityManager().getCallerClass(-1); }
@Test public void getCallerClass_shouldGetTheMostRecentlyCalledMethod() throws Exception { OpenmrsSecurityManager openmrsSecurityManager = new OpenmrsSecurityManager(); Class<?> callerClass = openmrsSecurityManager.getCallerClass(0); Assert.assertTrue("Oops, didn't get a junit type of class: " + callerClass, callerClass.getPackage().getName() .contains("junit")); }
@Test(expected = APIException.class) public void getCallerClass_shouldThrowAnErrorIfGivenASubzeroCallStackLevel() throws Exception { new OpenmrsSecurityManager().getCallerClass(-1); }