javajunitfitnesse-slim

FitNesse not invoking overloading method


I made a wrapper class MyClassFixture for a pojo MyClass by extending it, to made the initialization of its fields more user friendly. Eg. I want to use my own date format on wiki pages, and parse that date in the overloading setters. So instead of invoking setWorkDay(long millis) from MyClass I want to invoke setWorkDay(String formatedDate) from MyClassFixture and parse the formatedDate string and then invoke setWorkDay(long) of the parent MyClass.

This is working nicely when I run the test from the wiki page, but not working when I run it with JUnit runner. The error message I got:

Can't convert 2016-03-05 to long. Tried to invoke: foo.bar.MyClass.setWorkDay(long) -> void. On instance of: foo.bar.MyClassFixture

I've tried it with different String arguments, but always the setWorkDay(long) method gets invoked. Why is this?

Thanks!


Solution

  • I've found the answer in FitNesse code. It is matching the method name and the number of arguments, but not the type of arguments.

    The difference between the run with fitnesse-standalone.jar and with JUnit runner was caused by using different JRE implementations (IBM vs. Oracle). instance.getClass().getMethods() returned Methods in different order, FitNesse picks the last one.

    So the safe solution is not overloading but using different method names.