samedi 21 mars 2020

Java: Calling in main implemented Interface Methods from a jUnit - Test

I have the following function:

public static String s(B b) {
        int t = b.t();
        String r ="Hello ";
        for(String z:s) {
            boolean x=b.f(t,5);
            if(x) {
                r+=z;
            }
        }
        return r;
    }

Which takes in B - Interface

The Interface B - Methods int t() and boolean f(int a, int b) were implemented in the same class within main as the following:

public static void main(String[] args) {
        A.s(new B() {                            //A - Class
            @Override                            //B - Interface
            public int t() {
                return 15;
            }
            @Override
            public boolean f(int a, int b) {
                return true;
            }
        });
    }

Issue: How can i test the public static String s(B b) - function from a jUnit - test when the function asks for a interface as a parameter, when the interface methods were implemented in main?

The Class is called A, Interface: B

Aucun commentaire:

Enregistrer un commentaire