我正在尝试将 AbstractShiroTest 抽象类用于我的单元测试,如http://shiro.apache.org/testing.html中所述 我有我的测试类:
public class BeanTest extends AbstractShiroTest {
...
@Test
public void testShiro() {
Subject subjectUnderTest = createNiceMock(Subject.class);
expect(subjectUnderTest.isAuthenticated()).andReturn(true);
expect(subjectUnderTest.getPrincipal()).andReturn("cenap");
setSubject(subjectUnderTest);
assertTrue("Subject is not authenticated", SecurityUtils.getSubject().isAuthenticated());
assertNotNull("Subject principle null", SecurityUtils.getSubject().getPrincipal());
}
@AfterClass
public static void tearDownClass() {
tearDownShiro();
}
两个断言都失败了... SecurityUtils.getSubject() 返回某个对象,但该对象的 isAuthenticated() 方法返回 false 并且 getPrincipal() 方法返回 null。“期望”子句似乎不起作用。我错过了什么?