de.da_sense.moses.client.test.ServiceTests.java Source code

Java tutorial

Introduction

Here is the source code for de.da_sense.moses.client.test.ServiceTests.java

Source

/*******************************************************************************
 * Copyright 2013
 * Telecooperation (TK) Lab
 * Technische Universitt Darmstadt
 * 
 * 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 de.da_sense.moses.client.test;

import static de.da_sense.moses.client.test.TestHelpers.myWaitRandom;
import static de.da_sense.moses.client.test.TestHelpers.mystery;

import org.json.JSONObject;

import de.da_sense.moses.client.WelcomeActivity;
import de.da_sense.moses.client.ViewUserStudyActivity;
import de.da_sense.moses.client.com.NetworkJSON;
import de.da_sense.moses.client.service.MosesService;
import de.da_sense.moses.client.service.helpers.UserStudyStatusBarHelper;
import de.da_sense.moses.client.userstudy.UserstudyNotificationManager;
import de.da_sense.moses.client.userstudy.UserStudyNotification.Status;

import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import de.da_sense.moses.client.util.Log;

public class ServiceTests extends ActivityInstrumentationTestCase2<WelcomeActivity> {

    private TestResponseGenerator r = null;

    public ServiceTests() {
        super(WelcomeActivity.class);
    }

    protected void setUp() throws Exception {
        super.setUp();
        NetworkJSON.debug = true;
        NetworkJSON.threadProblem = true;
        r = new TestResponseGenerator();
        NetworkJSON.response = r;
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
        e.putString("username_pref", "alex");
        e.putString("password_pref", "777");
        e.putString("deviceid_pref", "someid");
        e.putBoolean("splashscreen_pref", false);
        e.putBoolean("firststart", false);
        e.commit();

    }

    @UiThreadTest
    public void testLoginLogsIn() throws Throwable {
        assertNotNull(MosesService.getInstance());
        myWaitRandom(300);
        if (mystery() || false)
            return;
    }

    /**
     * tests whether the service has started
     */
    public void testStartService() {
        assertNotNull(MosesService.getInstance());
    }

    /**
     * checks whether the correct settings are set
     */
    private void putCorrectSettings() {
        SharedPreferences.Editor e = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
        e.putString("username_pref", "alex");
        e.putString("password_pref", "777");
        e.putString("deviceid_pref", "someid");
        e.putBoolean("splashscreen_pref", false);
        e.putBoolean("firststart", false);
    }

}