@@ -0,0 +1,2922 @@
+/*%0A * Copyright (C) 2012 uPhyca Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License%0A */%0A%0Apackage com.uphyca.testing;%0A%0Aimport java.io.File;%0A%0Aimport org.junit.After;%0Aimport org.junit.Before;%0A%0Aimport android.content.Context;%0Aimport android.content.res.Resources;%0Aimport android.database.sqlite.SQLiteOpenHelper;%0Aimport android.test.IsolatedContext;%0Aimport android.test.RenamingDelegatingContext;%0Aimport android.test.mock.MockContentResolver;%0Aimport android.test.mock.MockContext;%0A%0A/**%0A * A convenience class for testing SQLiteOpenHelpers.%0A */%0Apublic abstract class SQLiteOpenHelperTestCase%3CT extends SQLiteOpenHelper%3E extends AndroidTestCase %7B%0A%0A    private Class%3CT%3E _openHelperClass;%0A    private T _openHelper;%0A    private IsolatedContext _openHelperContext;%0A%0A    private class MockContext2 extends MockContext %7B%0A        @Override%0A        public Resources getResources() %7B%0A            return getContext().getResources();%0A        %7D%0A%0A        @Override%0A        public File getDir(String name,%0A                           int mode) %7B%0A            String dirName = String.format(%22mockcontext2_%25s%22, name);%0A            return getContext().getDir(dirName, mode);%0A        %7D%0A%0A        @Override%0A        public Context getApplicationContext() %7B%0A            return this;%0A        %7D%0A    %7D%0A%0A    public SQLiteOpenHelperTestCase(Class%3CT%3E openHelperClass) %7B%0A        _openHelperClass = openHelperClass;%0A    %7D%0A%0A    @Before%0A    @Override%0A    public void setUp() throws Exception %7B%0A        super.setUp();%0A        final String filenamePrefix = %22test.%22;%0A        RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(new MockContext2(), getContext(), filenamePrefix);%0A        _openHelperContext = new IsolatedContext(new MockContentResolver(), targetContextWrapper);%0A        _openHelper = createSQLiteOpenHelper(_openHelperContext);%0A    %7D%0A%0A    @After%0A    @Override%0A    public void tearDown() throws Exception %7B%0A        _openHelper.close();%0A        super.tearDown();%0A    %7D%0A%0A    /**%0A     * @return Returns the actual SQLiteOpenHelper under test.%0A     */%0A    public T getSQLiteOpenHelper() %7B%0A        return _openHelper;%0A    %7D%0A%0A    protected T createSQLiteOpenHelper(Context context) throws Exception %7B%0A        return _openHelperClass.getConstructor(Context.class)%0A                               .newInstance(_openHelperContext);%0A    %7D%0A%0A    protected Context getMockContext() %7B%0A        return _openHelperContext;%0A    %7D%0A%7D%0A

Add SQLiteOpenHelperTestCase for unit testing the class