Code example for MockContentResolver

Methods: queryupdate

0
     
    public void testStats() { 
        ContentValues stat;
        stat = new ContentValues();
        stat.put("total_msges", 3);
        mRes.update(Uri.parse("content://foo.lounge/stats"), stat, null, null);
        stat.put("total_msges", 42);
        mRes.update(Uri.parse("content://foo.lounge/stats"), stat, null, null);
 
        stat = new ContentValues();
        stat.put("games_played", 5);
        mRes.update(Uri.parse("content://foo.lounge/stats"), stat, null, null);
        stat.put("games_played", 7);
        mRes.update(Uri.parse("content://foo.lounge/stats"), stat, null, null);
         
        stat = new ContentValues();
        stat.put("player_online", 42);
        mRes.update(Uri.parse("content://foo.lounge/stats"), stat, null, null);
 
        Cursor stats = mRes.query(Uri.parse("content://foo.lounge/stats"), null, null, null, null);
        assertEquals("There should always be only one set of stats", 1, stats.getCount());
        stats.moveToFirst();
        assertEquals("total messages should have been added", 45, stats.getInt(1));
        assertEquals("games played should have been added", 12, stats.getInt(2));
        assertEquals("player should be online", 42, stats.getInt(3));