<commit_before>package org.edx.mobile.test;

import android.content.Context;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;

import org.edx.mobile.core.EdxDefaultModule;
import org.edx.mobile.core.IEdxEnvironment;
import org.edx.mobile.logger.Logger;
import org.edx.mobile.util.Config;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import roboguice.RoboGuice;

/**
 * Created by rohan on 12/31/14.
 */
@Ignore
@RunWith(RobolectricGradleTestRunner.class)
public class BaseTestCase {

    protected final Logger logger = new Logger(getClass().getName());

    protected Context context;
    protected Config config;
    protected CustomGuiceModule module;
    @Before
    public void setUp() throws Exception {
        context = RuntimeEnvironment.application;
        config = createConfig();

        module = new CustomGuiceModule();
        glueInjections();
        print("Started Test Case: " + getClass().getName());
    }

    private void glueInjections() {
        addBindings();
        if ( !module.isEmpty()  ) {
            Injector injector = RoboGuice.getOrCreateBaseApplicationInjector(RuntimeEnvironment.application, RoboGuice.DEFAULT_STAGE,
                (Module) RoboGuice.newDefaultRoboModule(RuntimeEnvironment.application), Modules.override(new EdxDefaultModule(context)).with(module));
            inject(injector);
        }
    }

    /**
     * subclass should inject the properties marked as @Inject
     */
    protected void inject(Injector injector ){}

    protected void addBindings() {
        module.addBinding(IEdxEnvironment.class, Mockito.mock(IEdxEnvironment.class));
        module.addBinding(Config.class, config);
    }

    protected Config createConfig(){
        // Set up a new config instance that serves the mock host url
        JsonObject properties;
        try {
            InputStream in = context.getAssets().open("config/config.json");
            JsonParser parser = new JsonParser();
            JsonElement config = parser.parse(new InputStreamReader(in));<commit_msg>Fix IEdxEnvironment binding issue in tests caused by mocking<commit_after>package org.edx.mobile.test;

import android.content.Context;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.util.Modules;

import org.edx.mobile.core.EdxDefaultModule;
import org.edx.mobile.logger.Logger;
import org.edx.mobile.util.Config;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import roboguice.RoboGuice;

/**
 * Created by rohan on 12/31/14.
 */
@Ignore
@RunWith(RobolectricGradleTestRunner.class)
public class BaseTestCase {

    protected final Logger logger = new Logger(getClass().getName());

    protected Context context;
    protected Config config;
    protected CustomGuiceModule module;
    @Before
    public void setUp() throws Exception {
        context = RuntimeEnvironment.application;
        config = createConfig();

        module = new CustomGuiceModule();
        glueInjections();
        print("Started Test Case: " + getClass().getName());
    }

    private void glueInjections() {
        addBindings();
        if ( !module.isEmpty()  ) {
            Injector injector = RoboGuice.getOrCreateBaseApplicationInjector(RuntimeEnvironment.application, RoboGuice.DEFAULT_STAGE,
                (Module) RoboGuice.newDefaultRoboModule(RuntimeEnvironment.application), Modules.override(new EdxDefaultModule(context)).with(module));
            inject(injector);
        }
    }

    /**
     * subclass should inject the properties marked as @Inject
     */
    protected void inject(Injector injector ){}

    protected void addBindings() {
        module.addBinding(Config.class, config);
    }

    protected Config createConfig(){
        // Set up a new config instance that serves the mock host url
        JsonObject properties;
        try {
            InputStream in = context.getAssets().open("config/config.json");
            JsonParser parser = new JsonParser();
            JsonElement config = parser.parse(new InputStreamReader(in));
{'fraction_non_alphanumeric': 0.1001201441730076, 'fraction_numerical': 0.0024028834601521826, 'mean_word_length': 3.6036866359447006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7058625', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1393, 'n_words': 317}