Skip to content

Commit

Permalink
Merge pull request #2006 from wordpress-mobile/issue/985-make-sfactor…
Browse files Browse the repository at this point in the history
…y-private

fix #985 make sFactory private in factories
  • Loading branch information
nbradbury committed Dec 16, 2014
2 parents 56b4d80 + 8123436 commit 9abb0ad
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 480 deletions.
5 changes: 0 additions & 5 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,9 @@ dependencies {
compile 'commons-lang:commons-lang:2.6'
compile 'com.cocosw:undobar:1.6@aar'

compile('org.apache.httpcomponents:httpmime:4.1.+') {
exclude group: 'commons-logging', module: 'commons-logging'
}

compile 'com.mixpanel.android:mixpanel-android:4.3.0@aar'
compile 'com.mcxiaoke.volley:library:1.0.+'

androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.+'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
androidTestCompile 'org.objenesis:objenesis:2.1'
androidTestCompile 'org.mockito:mockito-core:+'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@
import org.wordpress.android.util.SystemServiceFactory;
import org.xmlrpc.android.XMLRPCFactory;

import java.lang.reflect.Field;

public class FactoryUtils {
public static void initWithTestFactories() {
// create test factories
XMLRPCFactory.sFactory = new XMLRPCFactoryTest();
RestClientFactory.sFactory = new RestClientFactoryTest();
OAuthAuthenticatorFactory.sFactory = new OAuthAuthenticatorFactoryTest();
SystemServiceFactory.sFactory = new SystemServiceFactoryTest();
forceFactoryInjection(XMLRPCFactory.class, new XMLRPCFactoryTest());
forceFactoryInjection(RestClientFactory.class, new RestClientFactoryTest());
forceFactoryInjection(OAuthAuthenticatorFactory.class, new OAuthAuthenticatorFactoryTest());
forceFactoryInjection(SystemServiceFactory.class, new SystemServiceFactoryTest());
AppLog.v(T.TESTS, "Mocks factories instantiated");
}

private static void forceFactoryInjection(Class klass, Object factory) {
try {
Field field = klass.getDeclaredField("sFactory");
field.setAccessible(true);
field.set(null, factory);
AppLog.v(T.TESTS, "Factory " + klass + " injected");
} catch (Exception e) {
AppLog.e(T.TESTS, "Can't inject test factory " + klass);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public PostUploadServiceTest() {
@Override
protected void setUp() throws Exception {
super.setUp();
testContext = getContext().createPackageContext("org.wordpress.android.test", Context.CONTEXT_IGNORE_SECURITY);
String namespace = BuildConfig.FLAVOR.equals("zbetagroup") ? "org.wordpress.android.beta"
: "org.wordpress.android";
testContext = getContext().createPackageContext(namespace, Context.CONTEXT_IGNORE_SECURITY);
targetContext = new RenamingDelegatingContext(getContext(), "test_");

// Init contexts
Expand Down Expand Up @@ -88,4 +90,4 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
cancelCount[0] == 1 && notifyCount[0] == 2);
}
*/
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class TestUtils {
private static String DATABASE_NAME = "wordpress";

public static SQLiteDatabase loadDBFromDump(Context targetContext, Context testContext, String filename) {
targetContext.deleteDatabase(DATABASE_NAME);
WordPress.wpDB = new WordPressDB(targetContext);

Field dbField;
Expand All @@ -39,10 +40,6 @@ public static SQLiteDatabase loadDBFromDump(Context targetContext, Context testC
SQLiteDatabase db = (SQLiteDatabase) dbField.get(WordPress.wpDB);
assertNotNull(db);

// delete and recreate DB
targetContext.deleteDatabase(DATABASE_NAME);
targetContext.openOrCreateDatabase(DATABASE_NAME, 0, null);

// Load file
InputStream is = testContext.getAssets().open(filename);
InputStreamReader inputStreamReader = new InputStreamReader(is);
Expand All @@ -51,7 +48,7 @@ public static SQLiteDatabase loadDBFromDump(Context targetContext, Context testC
if (TextUtils.isEmpty(line)) continue;
try {
db.execSQL(line);
} catch (android.database.sqlite.SQLiteException e ) {
} catch (android.database.sqlite.SQLiteException e) {
// ignore import errors
}
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9abb0ad

Please sign in to comment.