Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service-Test-for-application-package #282

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.opendatakit.Application;

import android.content.Context;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.junit.FixMethodOrder;
import org.opendatakit.services.R;
import org.opendatakit.services.application.Services;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ServicesTest {

private Services services;

@Rule
public final ODKServiceTestRule mServiceRule = new ODKServiceTestRule();

@Before
public void setUp() throws Exception {
services = new Services();
services.onCreate();
}

@After
public void tearDown() throws Exception {
}

@Test
public void OnCreate_initializesServices() {
assertNotNull(services);
}

@Test
public void GetApkDisplayNameResourceId() {
int apkDisplayNameResourceId = services.getApkDisplayNameResourceId();
assertEquals(R.string.app_name, apkDisplayNameResourceId);
}

@Test
public void SingletonInstanceInitialization() {
Context singleton = Services._please_dont_use_getInstance();
assertNotNull(singleton);
}

public class ODKServiceTestRule implements org.junit.rules.TestRule {
@Override
public org.junit.runners.model.Statement apply(final org.junit.runners.model.Statement base,
final org.junit.runner.Description description) {
return new org.junit.runners.model.Statement() {
@Override
public void evaluate() throws Throwable {
try {
beforeService();
base.evaluate();
} finally {
afterService();
}
}
};
}

protected void beforeService() {
}

protected void afterService() {
}
}
}