mockito - Method getReadableDatabase in android.database.sqlite.SQLiteOpenHelper not mocked -


i'd test methods inside databasehelper class. develop android studio. use mockito testing , got error message running test:

method getreadabledatabase in android.database.sqlite.sqliteopenhelper not mocked.

this databasehelper class:

public class databasehelper2 extends sqliteopenhelper {      //the android's default system path of application database.     private static string db_path = "/data/data/com.example.b.mywm/databases/";      private static string db_name = "429";      private sqlitedatabase mydatabase;      private final context mycontext;      /**      * constructor      */     public databasehelper2(context context) {         super(context, db_name, null, 1);         this.mycontext = context;     }      public void opendatabase() throws sqlexception {         //open database         string mypath = db_path + db_name;         mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly);     }      @override     public void oncreate(sqlitedatabase db) {     }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     }      @override     public synchronized void close() {         if(mydatabase != null) {             mydatabase.close();         }          super.close();     }     public list<topic> gettopics() {         sqlitedatabase db = this.getreadabledatabase();          arraylist<topic> topics = new arraylist<topic>();          int id = -1;         string description = "";          cursor c = db.rawquery("select * from" + "topics", null);          if (c.movetofirst()) {             id = c.getint(c.getcolumnindex("id"));             description = c.getstring(c.getcolumnindex("description"));              topic t = new topic(id, description);             topics.add(t);         }         c.close();          //  contact contact = new contact(integer.parseint(cursor.getstring(0)),         //        cursor.getstring(1), cursor.getstring(2));         // return contact         return topics;     } } 

my test:

@runwith(mockitojunitrunner.class) public class dbtest {      @mock     context mmockcontext;      @mock     databasehelper2 databasehelper;      @before     public void setup() {         databasehelper = new databasehelper2(mmockcontext);     }      @test     public void readstringfromcontext_localizedstring() {        list<topic> f = databasehelper.gettopics();     } } 


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -