0

I am new to Junit and trying to write unit testing for a class which has native methods.

public class TokenProvider {
    static {
        System.loadLibrary("mylib");
    }

    public Token list(String key) {
        TokenProvider tokenprovider = new TokenProvider();
        Token token = tokenprovider.listTokens(key);
        return token;
    }
    private native Token listTokens(String key); 
}

private native Token listTokens(String key); This method logic is there in mylib library which is written in CPP. I tried like this

public class TestTokenProvider {

    @Test
    public void testList() {
        TokenProvider tokenProvider = new TokenProvider();
        Token actual = tokenProvider.list(""); // key is passing as empty as it is not requested for this usecase
        Token expected = // need to get list of tokens eg: [{name: "token1", id: "123"}, {name: "token2", id: "1234"}]
        assertEquals(actual, expected);
    }
}

I am getting "java.lang.unsatisifiedLinkError" Error. Also help me to improve code coverage for TokenProvider.

Pramod K
  • 3
  • 4
  • Similar question : https://stackoverflow.com/questions/34571/how-do-i-test-a-class-that-has-private-methods-fields-or-inner-classes – Min Hyoung Hong Sep 08 '22 at 04:28

0 Answers0