aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/entity/TweetTest.java101
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/preference/SharedPreferenceHelperTest.java67
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/preference/UserPreferenceHelperTest.java52
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/twitter/TweetBuilderTest.java56
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java55
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/twitter/UserStreamListenerTest.java101
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/util/TwitterMock.java141
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapterTest.java88
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java63
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/MessageViewModelTest.java45
-rw-r--r--app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/StatusViewModelTest.java45
11 files changed, 0 insertions, 814 deletions
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/entity/TweetTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/entity/TweetTest.java
deleted file mode 100644
index b6629718..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/entity/TweetTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package net.lacolaco.smileessence.entity;
-
-import android.test.InstrumentationTestCase;
-import net.lacolaco.smileessence.util.TwitterMock;
-import twitter4j.TwitterObjectFactory;
-
-import java.util.EnumSet;
-
-public class TweetTest extends InstrumentationTestCase {
- TwitterMock mock;
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- }
-
- // begin: static methods
- public void testFetch() throws Exception {
- // register a Tweet
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- assertSame(sample, Tweet.fetch(sample.getId()));
- assertNull(Tweet.fetch(sample.getId() + 1));
- }
-
- public void testRemove() throws Exception {
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- Tweet.remove(sample.getId());
- assertNull(Tweet.fetch(sample.getId()));
- }
-
- public void testFromTwitterSingle() throws Exception {
- twitter4j.Status status = mock.getTweetRawMock();
- Tweet first = Tweet.fromTwitter(status, 0);
- Tweet second = Tweet.fromTwitter(status, 1);
- assertSame(first, second);
- }
- // end: static methods
-
- // begin: update
- public void testUpdateData() throws Exception {
- twitter4j.Status status = mock.getTweetRawMock();
- Tweet original = Tweet.fromTwitter(status, status.getUser().getId());
- assertEquals(status.getId(), original.getId());
- assertEquals(0, original.getFavoriteCount());
-
- String newJson = mock.getTweetJSONMock().replace("\"favorite_count\":0", "\"favorite_count\":100");
- assertTrue("[BUG] status.json is invalid", newJson.contains("\"favorite_count\":100"));
- twitter4j.Status updatedStatus = TwitterObjectFactory.createStatus(newJson);
-
- Tweet updated = Tweet.fromTwitter(updatedStatus, 12345L);
- assertEquals(100, updated.getFavoriteCount());
- assertTrue("favoriter list contains user_id 12345", updated.getFavoriters().contains(12345L));
- }
-
- public void testUpdateObserver() throws Exception {
- final O<EnumSet<RBinding>> changes = new O<>();
- twitter4j.Status status = mock.getTweetRawMock();
- Tweet original = Tweet.fromTwitter(status, 0);
- original.addObserver(this, changes_ -> changes.object = changes_);
-
- String newJson = mock.getTweetJSONMock().replace("\"favorite_count\":0", "\"favorite_count\":100");
- assertTrue("[BUG] status.json is invalid", newJson.contains("\"favorite_count\":100"));
- twitter4j.Status updatedStatus = TwitterObjectFactory.createStatus(newJson);
-
- Tweet.fromTwitter(updatedStatus, 0);
- assertTrue("changes contains REACTION_COUNT", changes.object.contains(RBinding.REACTION_COUNT));
- Tweet.fromTwitter(updatedStatus, 12345);
- assertTrue("changes contains FAVORITERS", changes.object.contains(RBinding.FAVORITERS));
- }
- // end: update
-
- // begin: instance methods
- public void testGetTwitterUrl() throws Exception {
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- assertTrue("twitter URL contains status ID", sample.getTwitterUrl().contains(String.valueOf(sample.getId())));
- }
-
- public void testAddFavoriter() throws Exception {
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- assertEquals(1, sample.getFavoriters().size());
- sample.addFavoriter(12345);
- assertEquals(2, sample.getFavoriters().size());
- }
-
- public void testRemoveFavoriter() throws Exception {
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- assertEquals(1, sample.getFavoriters().size());
- sample.removeFavoriter(0);
- assertEquals(0, sample.getFavoriters().size());
- }
-
- public void testGetEmbeddedStatusIds() throws Exception {
- Tweet sample = Tweet.fromTwitter(mock.getTweetRawMock(), 0);
- assertTrue(sample.getEmbeddedStatusIDs().contains(441249190841032704L));
- }
-
- // utility class
- static class O<T> {
- public T object;
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/preference/SharedPreferenceHelperTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/preference/SharedPreferenceHelperTest.java
deleted file mode 100644
index e5a517cb..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/preference/SharedPreferenceHelperTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.preference;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.test.InstrumentationTestCase;
-
-public class SharedPreferenceHelperTest extends InstrumentationTestCase {
-
- SharedPreferenceHelper helper;
-
- @Override
- public void setUp() throws Exception {
- //can't create on test context.
- helper = new SharedPreferenceHelper() {
- @Override
- protected SharedPreferences getPreferences() {
- return getInstrumentation().getTargetContext().getSharedPreferences("TestPreference", Context.MODE_PRIVATE);
- }
- };
- assertTrue(helper.set("test.sample", "test"));
- assertTrue(helper.set("test.empty", ""));
- }
-
- public void testGetProperty() throws Exception {
- String sample = helper.get("test.sample", "");
- assertEquals("test", sample);
- }
-
- public void testSetProperty() throws Exception {
- assertTrue(helper.set("test.sample", "test1"));
- assertEquals("test1", helper.get("test.sample", "notCorrect"));
- }
-
- public void testGetEmptyValue() throws Exception {
- String empty = helper.get("test.empty", "ax");
- assertEquals("", empty);
- }
-
- public void testNotExists() throws Exception {
- String notExists = helper.get("test.null", "no");
- assertEquals("no", notExists);
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/preference/UserPreferenceHelperTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/preference/UserPreferenceHelperTest.java
deleted file mode 100644
index 2b21b13c..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/preference/UserPreferenceHelperTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.preference;
-
-import android.test.AndroidTestCase;
-
-import net.lacolaco.smileessence.R;
-
-public class UserPreferenceHelperTest extends AndroidTestCase {
-
- private UserPreferenceHelper pref;
-
- @Override
- public void setUp() throws Exception {
- pref = UserPreferenceHelper.getInstance();
- }
-
- public void testNotFound() throws Exception {
- assertEquals("", pref.get(0, ""));
- }
-
- public void testUseDefault() throws Exception {
- assertNotSame(0, pref.get(R.string.key_setting_text_size, 10));
- }
-
- public void testPutAndGet() throws Exception {
- assertEquals(true, pref.set(R.string.key_test_preference, 10));
- assertEquals(10, pref.get(R.string.key_test_preference, 0));
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TweetBuilderTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TweetBuilderTest.java
deleted file mode 100644
index 7546ec0a..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TweetBuilderTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.twitter;
-
-import android.test.InstrumentationTestCase;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.entity.User;
-import net.lacolaco.smileessence.util.TwitterMock;
-
-public class TweetBuilderTest extends InstrumentationTestCase {
-
- TwitterMock mock;
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- }
-
- public void testBuilder() throws Exception {
- User user = mock.getUserMock();
- Tweet status = mock.getReplyMock();
- TweetBuilder builder = new TweetBuilder();
- assertEquals("", builder.buildText());
- builder.addScreenName(user.getScreenName());
- builder.setText("test");
- assertEquals("@laco0416 test", builder.buildText());
- builder.appendText(" #test");
- assertEquals("@laco0416 test #test", builder.buildText());
- builder.setInReplyToStatusID(status.getInReplyToStatusId());
- assertEquals(status.getInReplyToStatusId(), builder.build().getInReplyToStatusId());
- builder.setMediaPath("");
- assertNotNull(builder.build());
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java
deleted file mode 100644
index 9d9f9372..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/TwitterUtilsTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.twitter;
-
-import android.test.InstrumentationTestCase;
-import com.twitter.Validator;
-import junit.framework.Assert;
-
-public class TwitterUtilsTest extends InstrumentationTestCase {
-
- public void testLength() throws Exception {
- String text = "test";
- Assert.assertEquals(text.length(), new Validator().getTweetLength(text));
- text = "test.com";
- assertNotSame(text.length(), new Validator().getTweetLength(text));
- }
-/* TODO
- public void testURL() throws Exception {
- String screenName = "laco0416";
-
- assertEquals("https://twitter.com/laco0416", TwitterUtils.getUserHomeURL(screenName));
- assertEquals("http://favstar.fm/users/laco0416/recent", TwitterUtils.getFavstarRecentURL(screenName));
- assertEquals("http://aclog.koba789.com/laco0416/timeline", TwitterUtils.getAclogTimelineURL(screenName));
- assertEquals("http://twilog.org/laco0416", TwitterUtils.getTwilogURL(screenName));
- }
-
- public void testScreenNames() throws Exception {
- TwitterMock mock = new TwitterMock(getInstrumentation().getContext());
- Status retweetMock = mock.getRetweetMock();
- assertEquals(3, TwitterUtils.getScreenNames(retweetMock, null).size());
- assertEquals(2, TwitterUtils.getScreenNames(retweetMock, retweetMock.getUser().getScreenName()).size());
- }*/
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/UserStreamListenerTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/twitter/UserStreamListenerTest.java
deleted file mode 100644
index 7d97f51d..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/twitter/UserStreamListenerTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.twitter;
-
-import android.test.ActivityInstrumentationTestCase2;
-import net.lacolaco.smileessence.activity.MainActivity;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.entity.User;
-import net.lacolaco.smileessence.util.TwitterMock;
-import net.lacolaco.smileessence.viewmodel.EventViewModel;
-import twitter4j.Status;
-import twitter4j.StatusDeletionNotice;
-
-public class UserStreamListenerTest extends ActivityInstrumentationTestCase2<MainActivity> {
-
- TwitterMock mock;
- UserStreamListener listener;
-
- public UserStreamListenerTest() {
- super(MainActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- listener = new UserStreamListener(mock.getAccount());
- }
-
- public void testOnStatus() throws Exception {
- Status status = mock.getTweetRawMock();
- Container<Tweet> a = new Container<>();
- Container<Long> b = new Container<>();
- StatusFilter.getInstance().register(this, Tweet.class,
- gotVm -> a.object = gotVm,
- gotId -> b.object = gotId);
- listener.onStatus(status);
- assertEquals(Tweet.fromTwitter(status, 0), a.object);
- listener.onDeletionNotice(new StatusDeletionNotice() {
- @Override
- public long getStatusId() {
- return status.getId();
- }
-
- @Override
- public long getUserId() {
- return status.getUser().getId();
- }
-
- @Override
- public int compareTo(StatusDeletionNotice another) {
- return 0;
- }
- });
- assertEquals(status.getId(), (long) b.object);
- StatusFilter.getInstance().unregister(this);
- }
-
- public void testOnFavorited() throws Exception {
- final Status status = mock.getReplyRawMock();
- final twitter4j.User source = mock.getUserRawMock();
- Container<EventViewModel> a = new Container<>();
- StatusFilter.getInstance().register(this, EventViewModel.class,
- gotVm -> a.object = gotVm,
- null);
- listener.onFavorite(source, source, status);
- assertNotNull(a.object);
- assertSame(User.fromTwitter(source), a.object.getSource());
- assertSame(Tweet.fromTwitter(status, mock.getUserMock().getId()), a.object.getTargetObject());
- }
-
- @Override
- protected void tearDown() throws Exception {
- getActivity().forceFinish();
- }
-
- static class Container<T> {
- public T object;
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/util/TwitterMock.java b/app/src/androidTest/java/net/lacolaco/smileessence/util/TwitterMock.java
deleted file mode 100644
index a111c76e..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/util/TwitterMock.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.util;
-
-import android.content.Context;
-import android.content.res.AssetManager;
-import net.lacolaco.smileessence.data.Account;
-import net.lacolaco.smileessence.entity.DirectMessage;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.entity.User;
-import twitter4j.*;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Properties;
-
-public class TwitterMock {
-
- AssetManager assets;
-
- public TwitterMock(Context context) {
- assets = context.getAssets();
- }
-
- private String getJson(String fileName) throws IOException {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(assets.open(fileName)));
- StringBuilder builder = new StringBuilder();
- String str;
- while ((str = reader.readLine()) != null) {
- builder.append(str);
- }
- return builder.toString();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- return null;
- }
-
- private String getOAuthToken(String name) throws IOException {
- String filename = "tokens.properties";
- Properties props = new Properties();
- InputStream is = null;
- try {
- is = assets.open(filename);
- props.load(is);
- return props.getProperty(name);
- } catch (Exception e) {
- throw e;
- } finally {
- if (is != null) {
- is.close();
- }
- }
- }
-
- public String getTweetJSONMock() throws IOException, TwitterException {
- return getJson("status.json");
- }
-
- public Status getTweetRawMock() throws IOException, TwitterException, JSONException {
- return TwitterObjectFactory.createStatus(getTweetJSONMock());
- }
-
- public Tweet getTweetMock() throws IOException, TwitterException, JSONException {
- return Tweet.fromTwitter(getTweetRawMock(), getUserMock().getId());
- }
-
- public Status getReplyRawMock() throws IOException, TwitterException {
- return TwitterObjectFactory.createStatus(getJson("reply.json"));
- }
-
- public Tweet getReplyMock() throws IOException, TwitterException {
- return Tweet.fromTwitter(getReplyRawMock(), getUserMock().getId());
- }
-
- public Status getRetweetRawMock() throws IOException, TwitterException {
- return TwitterObjectFactory.createStatus(getJson("retweet.json"));
- }
-
- public Tweet getRetweetMock() throws IOException, TwitterException {
- return Tweet.fromTwitter(getRetweetRawMock(), getUserMock().getId());
- }
-
- public twitter4j.User getUserRawMock() throws IOException, TwitterException {
- return TwitterObjectFactory.createUser(getJson("user.json"));
- }
-
- public User getUserMock() throws IOException, TwitterException {
- return User.fromTwitter(getUserRawMock());
- }
-
- public twitter4j.DirectMessage getDirectMessageRawMock() throws IOException, TwitterException {
- return TwitterObjectFactory.createDirectMessage(getJson("directmessage.json"));
- }
-
- public DirectMessage getDirectMessageMock() throws IOException, TwitterException {
- return DirectMessage.fromTwitter(getDirectMessageRawMock());
- }
-
- public String getAccessToken() throws IOException, JSONException {
- return getOAuthToken("accessToken");
- }
-
- public String getAccessTokenSecret() throws IOException, JSONException {
- return getOAuthToken("accessTokenSecret");
- }
-
- public Account getAccount() throws IOException, TwitterException, JSONException {
- return Account.register(getAccessToken(), getAccessTokenSecret(), getUserMock().getId(), getUserMock().getScreenName());
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapterTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapterTest.java
deleted file mode 100644
index c37d3551..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapterTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.view.adapter;
-
-import android.test.ActivityInstrumentationTestCase2;
-import net.lacolaco.smileessence.activity.MainActivity;
-import net.lacolaco.smileessence.data.Account;
-import net.lacolaco.smileessence.util.TwitterMock;
-import net.lacolaco.smileessence.viewmodel.StatusViewModel;
-
-import java.util.Arrays;
-
-public class OrderedCustomListAdapterTest extends ActivityInstrumentationTestCase2<MainActivity> {
-
- TwitterMock mock;
- OrderedCustomListAdapter<StatusViewModel> adapter;
- Account account;
-
- public OrderedCustomListAdapterTest() {
- super(MainActivity.class);
- }
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- adapter = new OrderedCustomListAdapter<>(getActivity());
- account = mock.getAccount();
- }
-
- public void testAddItem() throws Exception {
- adapter.addItem(new StatusViewModel(mock.getReplyMock()));
- adapter.notifyDataSetChanged();
- assertEquals(1, adapter.getCount());
- }
-
- public void testUpdate() throws Exception {
- adapter.addItem(new StatusViewModel(mock.getReplyMock()));
- assertEquals(0, adapter.getCount());
- adapter.notifyDataSetChanged();
- assertEquals(1, adapter.getCount());
- }
-
- public void testAddItems() throws Exception {
- StatusViewModel viewModel1 = new StatusViewModel(mock.getReplyMock());
- StatusViewModel viewModel2 = new StatusViewModel(mock.getReplyMock());
- adapter.addItems(Arrays.asList(viewModel1, viewModel2));
- adapter.notifyDataSetChanged();
- assertEquals(2, adapter.getCount());
- }
-
- public void testRemoveItem() throws Exception {
- StatusViewModel viewModel1 = new StatusViewModel(mock.getReplyMock());
- StatusViewModel viewModel2 = new StatusViewModel(mock.getReplyMock());
- adapter.addItems(Arrays.asList(viewModel1, viewModel2));
- adapter.notifyDataSetChanged();
- assertEquals(2, adapter.getCount());
- adapter.removeItem(viewModel1);
- adapter.notifyDataSetChanged();
- assertEquals(1, adapter.getCount());
- }
-
- @Override
- protected void tearDown() throws Exception {
- getActivity().forceFinish();
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java
deleted file mode 100644
index 767b5961..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/EventViewModelTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.viewmodel;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.test.InstrumentationTestCase;
-import net.lacolaco.smileessence.R;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.entity.User;
-import net.lacolaco.smileessence.util.TwitterMock;
-
-import java.util.Locale;
-
-public class EventViewModelTest extends InstrumentationTestCase {
-
- TwitterMock mock;
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- }
-
- public void testNewInstance() throws Exception {
- Context context = getInstrumentation().getTargetContext();
- Tweet status = mock.getReplyMock();
- User source = mock.getUserMock();
- EventViewModel event = new EventViewModel(EventViewModel.EnumEvent.FAVORITED, source, status);
- assertEquals(source, event.getSource());
- assertEquals(status, event.getTargetObject());
- assertEquals(context.getString(R.string.format_event_favorited, source.getScreenName()), event.getFormattedString());
- event = new EventViewModel(EventViewModel.EnumEvent.RECEIVE_MESSAGE, source);
- Configuration config = context.getResources().getConfiguration();
- config.locale = Locale.ENGLISH;
- context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
- assertEquals(String.format("Received %s's message", source.getScreenName()), event.getFormattedString());
- config.locale = Locale.JAPANESE;
- context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
- assertEquals(String.format("%sからのDMを受信", source.getScreenName()), event.getFormattedString());
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/MessageViewModelTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/MessageViewModelTest.java
deleted file mode 100644
index e9d1acc9..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/MessageViewModelTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.viewmodel;
-
-import android.test.InstrumentationTestCase;
-import net.lacolaco.smileessence.entity.DirectMessage;
-import net.lacolaco.smileessence.util.TwitterMock;
-
-public class MessageViewModelTest extends InstrumentationTestCase {
-
- TwitterMock mock;
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- }
-
- public void testNewInstance() throws Exception {
- DirectMessage dm = mock.getDirectMessageMock();
- MessageViewModel viewModel = new MessageViewModel(dm);
- assertEquals(dm, viewModel.getDirectMessage());
- }
-}
diff --git a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/StatusViewModelTest.java b/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/StatusViewModelTest.java
deleted file mode 100644
index bfb54b60..00000000
--- a/app/src/androidTest/java/net/lacolaco/smileessence/viewmodel/StatusViewModelTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2014 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.viewmodel;
-
-import android.test.InstrumentationTestCase;
-import net.lacolaco.smileessence.entity.Tweet;
-import net.lacolaco.smileessence.util.TwitterMock;
-
-public class StatusViewModelTest extends InstrumentationTestCase {
-
- TwitterMock mock;
-
- @Override
- public void setUp() throws Exception {
- mock = new TwitterMock(getInstrumentation().getContext());
- }
-
- public void testTweetObject() throws Exception {
- Tweet tw = mock.getReplyMock();
- StatusViewModel status = new StatusViewModel(tw);
- assertSame(tw, status.getTweet());
- }
-}