Skip to content

Commit

Permalink
bug fix.WXSQLiteOpenHelper mem leak (alibaba#1515)
Browse files Browse the repository at this point in the history
* bug fix.WXSQLiteOpenHelper mem leak

* update test

* update test

* remove unused code
  • Loading branch information
Rowandjj authored and sospartan committed Oct 26, 2016
1 parent 56372c9 commit 712dcf8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void execute(Runnable runnable) {
}

public DefaultWXStorage(Context context) {
this.mDatabaseSupplier = WXSQLiteOpenHelper.getInstance(context);
this.mDatabaseSupplier = new WXSQLiteOpenHelper(context);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ public class WXSQLiteOpenHelper extends SQLiteOpenHelper {
static SimpleDateFormat sDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());


private static WXSQLiteOpenHelper sInstance;

private Context mContext;
private SQLiteDatabase mDb;

Expand All @@ -249,23 +247,12 @@ public class WXSQLiteOpenHelper extends SQLiteOpenHelper {
+ ")";


private WXSQLiteOpenHelper(Context context) {
public WXSQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.mContext = context;
}

public static WXSQLiteOpenHelper getInstance(Context context) {
if (context == null) {
WXLogUtils.e(TAG_STORAGE,"can not get context instance...");
return null;
}
if (sInstance == null) {
sInstance = new WXSQLiteOpenHelper(context);
}
return sInstance;
}

SQLiteDatabase getDatabase() {
public SQLiteDatabase getDatabase() {
ensureDatabase();
return mDb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
package com.taobao.weex.appfram.storage;

import com.taobao.weappplus_sdk.BuildConfig;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -218,8 +219,10 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static org.powermock.api.mockito.PowerMockito.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyMapOf;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

/**
* Created by sospartan on 7/28/16.
Expand All @@ -238,14 +241,15 @@ public class DefaultWXStorageTest {
public PowerMockRule rule = new PowerMockRule();

@Before
public void setup(){
public void setup() throws Exception{
supplier = Mockito.mock(WXSQLiteOpenHelper.class);
listener = Mockito.mock(IWXStorageAdapter.OnResultReceivedListener.class);
storage = new DefaultWXStorage(RuntimeEnvironment.application);

mockStatic(WXSQLiteOpenHelper.class);

PowerMockito.when(WXSQLiteOpenHelper.getInstance(RuntimeEnvironment.application)).thenReturn(supplier);
PowerMockito.whenNew(WXSQLiteOpenHelper.class)
.withArguments(RuntimeEnvironment.application)
.thenReturn(supplier);
}


Expand Down

0 comments on commit 712dcf8

Please sign in to comment.