0

下面的代码不起作用

@BeforeClass    
public static void setUp() {
            service=new BusManager();
            logger = mock(Logger.class);
            when(logger.isDebugEnabled()).thenReturn(true);
            doAnswer(new MakePersistentCallback()).when(logger).debug(argStr.capture());
            mockStatic(Logger.class);
            when(Logger.getLogger(argClass.capture())).thenReturn(logger);
            entityMngr = mock(IEntityMgr.class);

            applicationBusManager = mock(ApplicationBusManager.class);
            antityManagerFactory = mock(EntityManagerFactory.class);
            applicationEntityMgr=mock(ApplicationEntityMgr.class);
            userApplicationEntityMgr=mock(UserApplicationEntityMgr.class);
            disBusManager=mock(DisBusManager.class);



            ReflectionTestUtils.setField(service,"entityManagerFactory",entityManagerFactory);
            ReflectionTestUtils.setField(service,"applicationBusManager",applicationBusManager); 
            ReflectionTestUtils.setField(service,"disBusManager",disBusManager); 



            when(entityManagerFactory.getEntityManager("applicationEntityMgr")).thenReturn(applicationEntityMgr);

            when(entityManagerFactory.getEntityManager("applicationEntityMgr")).thenReturn(applicationEntityMgr);


        }

它显示以下错误。我的目标是提供 cobertura 报告以及 junits。我还必须涵盖记录器......所以我在测试类的初始化之前放置记录器代码..

  java.lang.NullPointerException
        at org.apache.commons.logging.impl.Log4JLogger.isDebugEnabled(Log4JLogger.java:299)
        at org.springframework.test.util.ReflectionTestUtils.setField(ReflectionTestUtils.java:109)
        at org.springframework.test.util.ReflectionTestUtils.setField(ReflectionTestUtils.java:81)
        at 

使用我们的记录器模拟代码工作正常..但我也需要工作记录器..

4

1 回答 1

0

虽然调试反射工具是它产生问题的地方。所以我确实使用测试类的setter方法注入这些对象并运行它工作正常..

于 2013-05-30T11:45:16.440 回答