dimanche 10 juillet 2016

JUnit 4 Test Method with local inner class is inconsistent across Test Cases

OK, I searched as best I could for this and couldn't find anything. I'm a first-time asker so be gentle. :p

Within one test case I have a test method to test a given event listener method when it gets fired.

@Test
public void testFireEventDoingSomething() {

   class LocalDoingListener extends DoingAdapter {

                LocalDoingListener() {
                    super();
                }
                public void onStartedDoingSomething(DoingEvent event) {
                    Assert.assertEquals(DoingClass.STARTED_DOING_SOMETHING, event.getDoingStatus());
                }
            }

            DoingListener listener = new LocalDoingListener();
            DoingSupport support = new DoingSupport(new DoingClass());
            support.addDoingListener(listener);
            support.fireStartedDoingSomething();
        }

The problem I have is this: this exact pattern is used in another test case (in the same project) for another event listener and it works perfectly well, but in the test case I have issues with I get (from the test report) java.lang.Exception: Test class should have exactly one public constructor.

I really don't understand why this pattern works in one test case but not in another - I even tried taking the constructor out, but it made no difference. Has anyone run into this issue and if so, how did you solve it?

Many thanks.

Aucun commentaire:

Enregistrer un commentaire