<commit_before>/*
 * Copyright (C) 2013 yvolk (<NAME>), http://yurivolkov.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.andstatus.app.context;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;

import org.andstatus.app.account.PersistentAccounts;
import org.andstatus.app.data.AssertionData;
import org.andstatus.app.database.DatabaseHolder;
import org.andstatus.app.net.http.HttpConnection;
import org.andstatus.app.notification.NotificationData;
import org.andstatus.app.notification.NotificationEventType;
import org.andstatus.app.notification.Notifier;
import org.andstatus.app.origin.PersistentOrigins;
import org.andstatus.app.service.ConnectionState;
import org.andstatus.app.timeline.meta.PersistentTimelines;
import org.andstatus.app.timeline.meta.Timeline;
import org.andstatus.app.util.InstanceId;
import org.andstatus.app.util.MyLog;

import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * This is kind of mock of the concrete implementation 
 * @author <EMAIL>
 */
public class MyContextForTest implements MyContext {
    final long instanceId = InstanceId.next();
    private volatile MyContext myContext = null;
    private final Set<AssertionData> dataSet = new CopyOnWriteArraySet<>();
    private volatile Class<? extends HttpConnection> httpConnectionMockClass = null;
    private volatile HttpConnection httpConnectionMockInstance = null;
    private volatile ConnectionState mockedConnectionState = ConnectionState.UNKNOWN;
    private final Map<NotificationEventType, NotificationData> androidNotifications = new ConcurrentHashMap<>();

    public MyContextForTest setContext(MyContext myContextIn) {
        MyContext myContext2 = myContextIn;
        for (int i = 0; i < 100; i++) {
            myContext = myContext2;
            if (myContext2 == null || !MyContextForTest.class.isAssignableFrom(myContext2.getClass())) {
                break;
            }
            myContext2 = ((MyContextForTest) myContext2).myContext;
        }
        if (myContext == null) {
            myContext = MyContextImpl.newEmpty(this);
        }
        return this;
    }

    public void setHttpConnectionMockClass(Class<? extends HttpConnection> httpConnectionMockClass) {
        this.httpConnectionMockClass = httpConnectionMockClass;
    }

    public void setHttpConnectionMockInstance(HttpConnection httpConnectionMockInstance) {
        this.httpConnectionMockInstance = httpConnectionMockInstance;
    }

    @Override
    public MyContext newInitialized(Object initializer) {
        return new MyContextForTest().setContext(myContext.newInitialized(initializer));
    }

    @Override
    public MyContext newCreator(Context context, Object initializer) {
        return new MyContextForTest().setContext(myContext.newCreator(context, initializer));
    }

    @Override
    public boolean initialized() {
        return myContext != null && myContext.initialized();
    }

    @Override
    public boolean isReady() {
        return myContext.isReady();
    }

    @Override
    public boolean isTestRun() {
        return true;
    }

    @Override
    public MyContextState state() {
        return myContext.state();
    }
<commit_msg>Fixed MyContextForTest<commit_after>/*
 * Copyright (C) 2013 yvolk (<NAME>), http://yurivolkov.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.andstatus.app.context;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;

import org.andstatus.app.account.PersistentAccounts;
import org.andstatus.app.data.AssertionData;
import org.andstatus.app.database.DatabaseHolder;
import org.andstatus.app.net.http.HttpConnection;
import org.andstatus.app.notification.NotificationData;
import org.andstatus.app.notification.NotificationEventType;
import org.andstatus.app.notification.Notifier;
import org.andstatus.app.origin.PersistentOrigins;
import org.andstatus.app.service.ConnectionState;
import org.andstatus.app.timeline.meta.PersistentTimelines;
import org.andstatus.app.timeline.meta.Timeline;
import org.andstatus.app.util.InstanceId;
import org.andstatus.app.util.MyLog;

import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * This is kind of mock of the concrete implementation 
 * @author <EMAIL>
 */
public class MyContextForTest implements MyContext {
    final long instanceId = InstanceId.next();
    private volatile MyContext myContext = null;
    private final Set<AssertionData> dataSet = new CopyOnWriteArraySet<>();
    private volatile Class<? extends HttpConnection> httpConnectionMockClass = null;
    private volatile HttpConnection httpConnectionMockInstance = null;
    private volatile ConnectionState mockedConnectionState = ConnectionState.UNKNOWN;
    private final Map<NotificationEventType, NotificationData> androidNotifications = new ConcurrentHashMap<>();

    public MyContextForTest setContext(MyContext myContextIn) {
        MyContext myContext2 = myContextIn;
        for (int i = 0; i < 100; i++) {
            myContext = myContext2;
            if (myContext2 == null || !MyContextForTest.class.isAssignableFrom(myContext2.getClass())) {
                break;
            }
            myContext2 = ((MyContextForTest) myContext2).myContext;
        }
        if (myContext == null) {
            myContext = MyContextImpl.newEmpty(this);
        }
        return this;
    }

    public void setHttpConnectionMockClass(Class<? extends HttpConnection> httpConnectionMockClass) {
        this.httpConnectionMockClass = httpConnectionMockClass;
    }

    public void setHttpConnectionMockInstance(HttpConnection httpConnectionMockInstance) {
        this.httpConnectionMockInstance = httpConnectionMockInstance;
    }

    @Override
    public MyContext newInitialized(Object initializer) {
        MyContextForTest context = new MyContextForTest();
        context.dataSet.addAll(dataSet);
        context.httpConnectionMockClass = httpConnectionMockClass;
        context.httpConnectionMockInstance = httpConnectionMockInstance;
        context.mockedConnectionState = mockedConnectionState;
        context.androidNotifications.putAll(androidNotifications);
        context.setContext(myContext.newInitialized(initializer));
        return context;
    }

    @Override
    public MyContext newCreator(Context context, Object initializer) {
        return new MyContextForTest().setContext(myContext.newCreator(context, initializer));
    }

    @Override
    public boolean initialized() {
        return myContext != null && myContext.initialized();
    }

    @Override
    public boolean isReady() {
        return myContext.isReady();
    }

    @Override
    public boolean isTestRun() {
        return true;
    }

    @Override
    public MyContextState state() {
        return myContext.state();
    }

{'fraction_non_alphanumeric': 0.08552873422374709, 'fraction_numerical': 0.004411224114691827, 'mean_word_length': 3.8612269207861822, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6037124', 'n_tokens_mistral': 2161, 'n_tokens_neox': 2134, 'n_words': 561}