Giter Club home page Giter Club logo

Comments (5)

scottyab avatar scottyab commented on May 30, 2024

I've not used Mockito, can you test the standard Shared Preferences ok? if so could you paste a code sample or link to example. thx

from secure-preferences.

IgorGanapolsky avatar IgorGanapolsky commented on May 30, 2024

The error actually happens because I am running my unit tests on the JVM, and hence don't access to a Context (which SecurePreferences requires).

from secure-preferences.

scottyab avatar scottyab commented on May 30, 2024

Ok, understood. But my question still stands if you can show me a test with config working using the standard Shared Preferences then I can see about getting securePreferences working. However if you cannot test standard Shared Preferences then this is not something this library is going to be able to solve.

from secure-preferences.

danilodequeiroz avatar danilodequeiroz commented on May 30, 2024

@IgorGanapolsky How did you solved this situation ?

from secure-preferences.

pedrodimoura avatar pedrodimoura commented on May 30, 2024

I am facing the same problem.
Its really weird!

val sp = SecurePreferences(context, context.packageName, PREFS)

I can test SharedPreferences normally but, when I try to get an instance of SecurePreferences with a mocked context throws an NullPointerException in line 85 because its a mocked context and the getDeviceSerialNumber cannot get an instance of ContextResolver in this method:

private static String getDeviceSerialNumber(Context context) {
        try {
            String deviceSerial = (String)Build.class.getField("SERIAL").get((Object)null);
            return TextUtils.isEmpty(deviceSerial) ? Secure.getString(context.getContentResolver(), "android_id") : deviceSerial;
        } catch (Exception var2) {
            return Secure.getString(context.getContentResolver(), "android_id");
        }
    }

I don't know if I am doing something wrong, but, my tests are not passing because of this problem and I am close to delete this library of my project because of that.

from secure-preferences.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.