Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Add tests #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ test:
# copy the build outputs to artifacts
- cp -r lib/build/outputs $CIRCLE_ARTIFACTS
# copy the test results to the test results directory.
#- cp -r lib/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
- cp -r lib/build/test-results/* $CIRCLE_TEST_REPORTS

5 changes: 3 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 22
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 22
targetSdkVersion 21
versionName "1.8"
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/jp/mixi/android/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Constants {
/** android2.2のSDKバージョン番号 */
static final int SUPPORTED_SDK_VERSION = 8;
/** mixiAndroidSDKのバージョン番号 */
static final String VERSION = "1.8";
static final String VERSION = BuildConfig.VERSION_NAME;
/** SDKからアクセスする際のユーザーエージェント */
static final String USER_AGENT =
System.getProperties().getProperty("http.agent") + " mixi-Android-SDK/" + VERSION;
Expand Down
30 changes: 30 additions & 0 deletions lib/src/test/java/jp/mixi/android/sdk/ConfigTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package jp.mixi.android.sdk;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

/**
* Created by Hideyuki.Kikuma on 15/08/25.
*/
@RunWith(RobolectricGradleTestRunner.class)
@org.robolectric.annotation.Config(constants = BuildConfig.class)
public class ConfigTest {

private static final int DEFAULT_CONNECTION_TIMEOUT = 20000;
private static final int DEFAULT_SOCKET_TIMEOUT = 20000;

@Test
public void defaultConfig() {
Config config = new Config();
assertThat(config.selector, is(Config.APPLICATION));
assertThat(config.clientId, is(nullValue()));
assertThat(config.connectionTimeout, is(DEFAULT_CONNECTION_TIMEOUT));
assertThat(config.socketTimeout, is(DEFAULT_SOCKET_TIMEOUT));
assertThat(config.version, is(BuildConfig.VERSION_NAME));
}
}
56 changes: 56 additions & 0 deletions lib/src/test/java/jp/mixi/android/sdk/ConstantsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package jp.mixi.android.sdk;

import android.os.Build;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
* Created by Hideyuki.Kikuma on 15/08/25.
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
public class ConstantsTest {
private static final String AGENT_PROPERTY_NAME = "http.agent";
private static final String AGENT_PROPERTY_VALUE = "testAgent";

@BeforeClass
public static void testSetUp() {
System.getProperties().setProperty(AGENT_PROPERTY_NAME, AGENT_PROPERTY_VALUE);
}

@Before
public void setUp() throws Exception {

}

@After
public void tearDown() throws Exception {

}

@Test
public void testSUPPORTED_SDK_VERSION() throws Exception {
assertThat(Constants.SUPPORTED_SDK_VERSION, is(Build.VERSION_CODES.FROYO));
}

@Test
public void testVERSION() throws Exception {
assertThat(Constants.VERSION, is(BuildConfig.VERSION_NAME));
}

@Test
public void testUSER_AGENT() throws Exception {
assertThat(Constants.USER_AGENT, is(AGENT_PROPERTY_VALUE + " mixi-Android-SDK/" + BuildConfig.VERSION_NAME));

}

}