开发者

Junit testing issue with NullPoint. and BeanFactory!

开发者 https://www.devze.com 2023-02-23 06:13 出处:网络
Hey having problem finishing off unit test. My problem is with my code I want to set a timeout to say 10000. But cant use \'magic number\' as they say so use this method inside code to call the value

Hey having problem finishing off unit test. My problem is with my code I want to set a timeout to say 10000. But cant use 'magic number' as they say so use this method inside code to call the value

public int getConnectionTimeout() {
    final Properties p = (Properties) SpringUtility.getBean("common.properties");
    return Integer.valueOf((String) p.get("connect.timeout"));
    //return 10000;
}

If I use the commented out return value(10000) tests work great. But the other gives me beanfactory error. So next in my unit test I decide to try and override the getConnectionTimeout() as follows:

cct = new ClientConnectionTester() {

        @Override
 开发者_Python百科       public int getConnectionTimeout() {
            return 10000;
        }
    };

Now its giving me null pointer, so clearly I'm missing something but cant put finger on it, thanks.

the NullPointer is coming from line 82 shown below

return Integer.valueOf((String) p.get("connect.timeout"));

stack trace

java.lang.NullPointerException
    at com.btisystems.pronx.ems.resources.utility.ClientConnectionTesterTest.verifyActiveConnection(ClientConnectionTesterTest.java:82)

But if use @Override call, I get NullPointer at

cct.getConnectionTimeout();

Was thinking should I mock the call, just dont understand why the @override is not working even tou I know its a bit of a hack :P

0

精彩评论

暂无评论...
验证码 换一张
取 消