0

Listbox is null

asked 2014-08-29 10:58:07 +0800

agazerboy gravatar image agazerboy
1 1

updated 2014-08-31 16:38:49 +0800

I am trying to write a test-case without using a ZUL file for now. I have a very basic function with the following lines.

Class to initialize Listbox:

public class TestComposer {

    public void listboxTest(){

        ListModelList model = new ListModelList();
        Listbox lbOne = new Listbox();
        lbOne.setModel(model);
        lbOne.setMultiple(true);

        System.out.println(lbOne); 

        System.out.println(model); 

    }

}

Test-case

public class testSuit {
    static ZatsEnvironment env; 

    @BeforeClass
    public static void init() {
        System.out.println("Setting server space.");
        env = new DefaultZatsEnvironment("/main/webapp/WEB-INF");
        env.init("/main/webapp");           

    }

    @AfterClass
    public static void end() {
        env.destroy();
    }

    @After
    public void after() {
        env.cleanup();
    }

    @Test
    public void test() {
        TestComposer tc = new TestComposer();

        tc.listboxTest();
    }
}

This piece of code will produce a null pointer exception. It shows that lbOne is null. Is there a way to use listbox without calling/using a ZUL file?

Stack trace:

java.lang.NullPointerException at org.zkoss.zk.ui.event.Events.postEvent(Events.java:383) at org.zkoss.zk.ui.event.Events.postEvent(Events.java:432) at org.zkoss.zk.ui.event.Events.postEvent(Events.java:366) at org.zkoss.zul.Listbox.postOnInitRender(Listbox.java:2501) at org.zkoss.zul.Listbox.setModel(Listbox.java:2266) at test.TestComposer.listboxTest(TestComposer.java:12) at test.testSuit.test(testSuit.java:75) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Line/trace of the NPE error

test.TestComposer.listboxTest(TestComposer.java:12) at test.testSuit.test(testSuit.java:75) at 
lbOne.setModel(model);

PS: I am using ZK web framework. I am using a testing tool that can't capture the traces in zats simulated environment. Thus, I want to directly call these methods without depending on ZUL files.

Thanks.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-08-31 01:14:18 +0800

Darksu gravatar image Darksu
1991 1 4

updated 2014-08-31 01:14:51 +0800

Hello agazerboy,

I believe that by using junit and zats, it will be very difficult to accomplish your task.

If I find something out, i will update the forum.

Best Regards,

Darksu

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-08-29 10:58:07 +0800

Seen: 24 times

Last updated: Aug 31 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More