0
private final SampleFormatter sampleFormatter = new SampleFormatter() {

    @Override
    public String formatDouble (int tag, double Value, int pre) { 
        if (Double.isNaN(Value)) {
            return "NaN";
        } 
        if (Value == 0.0D) {
            return "0";
        } else {
            return df.format(Value);
        }
    }

}

Here sample formatter is an interface and its method is implemented here.

How to get coverage for this format Double() method by writing testng test case.

  • There is no private final method in the code you posted. – Lesiak Jun 15 '23 at 10:51
  • Sorry, Its not a private final method ,I have misunderstood that ,it is a private final anonymous class. – Keerthi Senthil Jun 15 '23 at 18:34
  • Either test through public methods that use this private field, or use a (package private) named class. If coverage is your goal, I would go with the latter. While getting access to this field via reflection is possible, it is far from elegant - your test will get mor complex than class under test. – Lesiak Jun 15 '23 at 21:07

0 Answers0