Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.a494studios.koreanconjugator;

import android.content.res.AssetManager;

import androidx.test.core.app.ApplicationProvider;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class MockReader {
public static final String FAVORITES = "favorites_response.json";
public static final String ENTRY = "entry_response.json";
public static final String CONJUGATIONS = "conjugations_response.json";
public static final String CONJUGATIONS_HONORIFIC = "conjugations_honorific_response.json";
public static final String WOD = "wod_response.json";


public static String readStringFromFile(String fileName) {
StringBuilder builder = new StringBuilder();

try {
InputStream inputStream = ApplicationProvider.getApplicationContext().getAssets().open(fileName, AssetManager.ACCESS_BUFFER);
DataInputStream in = new DataInputStream(inputStream);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));

String line;
while((line = reader.readLine()) != null) {
builder.append(line);
}

in.close();
} catch (IOException e) {
e.printStackTrace();
}

return builder.toString();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

import com.a494studios.koreanconjugator.ConjugationQuery;
import com.a494studios.koreanconjugator.MockedResponses;
import com.a494studios.koreanconjugator.MockReader;
import com.a494studios.koreanconjugator.R;
import com.a494studios.koreanconjugator.conjugations.ConjugationActivity;
import com.a494studios.koreanconjugator.conjugations.ConjugationCardsAdapter;
import com.a494studios.koreanconjugator.fragment.ConjugationFragment;
import com.a494studios.koreanconjugator.parsing.Server;
import com.a494studios.koreanconjugator.rules.MockServerRule;
import com.a494studios.koreanconjugator.rules.StubIntentsRule;
Expand All @@ -33,6 +33,7 @@

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.a494studios.koreanconjugator.MockReader.readStringFromFile;
import static com.a494studios.koreanconjugator.Utils.assertBodyContains;
import static com.a494studios.koreanconjugator.Utils.setChecked;
import static junit.framework.TestCase.assertEquals;
Expand Down Expand Up @@ -74,8 +75,8 @@ public void setup() {
IdlingRegistry.getInstance().register(idler);

// Enqueue responses
serverRule.server.enqueue(new MockResponse().setBody(MockedResponses.CONJUGATIONS));
serverRule.server.enqueue(new MockResponse().setBody(MockedResponses.CONJUGATIONS_HONORIFIC));
serverRule.server.enqueue(new MockResponse().setBody(readStringFromFile(MockReader.CONJUGATIONS)));
serverRule.server.enqueue(new MockResponse().setBody(readStringFromFile(MockReader.CONJUGATIONS_HONORIFIC)));

// Start test
activityRule.launchActivity(null);
Expand Down Expand Up @@ -121,7 +122,7 @@ public void test_honorificSwitch() throws InterruptedException {

ConjugationCardsAdapter adapter = (ConjugationCardsAdapter)recyclerView.getAdapter();
assertEquals(numItems, adapter.getItemCount());
List<ConjugationQuery.Conjugation> conjugations = adapter.getItem(0);
List<ConjugationFragment> conjugations = adapter.getItem(0);
assertBodyContains(serverRule.server.takeRequest(2, TimeUnit.SECONDS),
"\"honorific\":true");
assertTrue(conjugations.get(0).honorific());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import androidx.test.rule.ActivityTestRule;

import com.a494studios.koreanconjugator.MockApplication;
import com.a494studios.koreanconjugator.MockedResponses;
import com.a494studios.koreanconjugator.MockReader;
import com.a494studios.koreanconjugator.R;
import com.a494studios.koreanconjugator.conjugations.ConjugationActivity;
import com.a494studios.koreanconjugator.display.DisplayActivity;
Expand Down Expand Up @@ -46,6 +46,7 @@
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra;
import static androidx.test.espresso.matcher.ViewMatchers.*;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static com.a494studios.koreanconjugator.MockReader.readStringFromFile;
import static com.a494studios.koreanconjugator.Utils.nthChildOf;
import static com.a494studios.koreanconjugator.Utils.testActionBar;
import static org.hamcrest.Matchers.allOf;
Expand Down Expand Up @@ -88,15 +89,16 @@ public void stubIntents() throws IOException {
testApp.setServerUrl(server.url("/").toString());

// Enqueue responses
server.enqueue(new MockResponse().setBody(MockedResponses.ENTRY));
server.enqueue(new MockResponse().setBody(MockedResponses.CONJUGATIONS));
server.enqueue(new MockResponse().setBody(readStringFromFile(MockReader.ENTRY)));
server.enqueue(new MockResponse().setBody(readStringFromFile(MockReader.FAVORITES)));

// Write favorites in SharedPreferences
Context context = getInstrumentation().getTargetContext();
ArrayList<Favorite> favs = new ArrayList<>();
favs.add(new Favorite("Past","declarative past informal high",false));
favs.add(new Favorite("Present","declarative present informal high",false));
favs.add(new Favorite("Present Honorific","declarative present informal high",true));
favs.add(new Favorite("Future","declarative future informal high",false));
favs.add(new Favorite("Verbs only","determiner past",false));
com.a494studios.koreanconjugator.utils.Utils.setFavorites(favs,context);

// Start test
Expand All @@ -118,22 +120,24 @@ public void overflowOptions() {
@Test
public void contents_areDisplayed() {
// Term and POS
onView(ViewMatchers.withId(R.id.word_info_term)).check(matches(withText("가다")));
onView(withId(R.id.word_info_pos)).check(matches(withText("Verb")));
onView(ViewMatchers.withId(R.id.word_info_term)).check(matches(withText("춥다")));
onView(withId(R.id.word_info_pos)).check(matches(withText("Adjective")));

// Definitions
onView(nthChildOf(withId(R.id.word_info_recycler), 0))
.check(matches(withText("to go")));
.check(matches(withText("(usually, of weather) (to be) cold")));
onView(nthChildOf(withId(R.id.word_info_recycler), 1))
.check(matches(withText("second definition")));
onView(nthChildOf(withId(R.id.word_info_recycler), 2))
.check(matches(withText("third definition")));

// Show all definitions
onView(withText("1 MORE")).perform(click());
onView(withText("2 MORE")).perform(click());

onView(nthChildOf(withId(R.id.word_info_recycler), 3))
.check(matches(withText("fourth definition")));
onView(nthChildOf(withId(R.id.word_info_recycler), 4))
.check(matches(withText("fifth definition")));

onView(withText("COLLAPSE")).perform(click());

Expand All @@ -143,9 +147,9 @@ public void contents_areDisplayed() {
.check(matches(withText("Examples")));

List<Pair<String, String>> examples = Arrays.asList(
new Pair<>("가자!", "Let's go!"),
new Pair<>("Second sentence", "Second translation"),
new Pair<>("Third sentence", "Third translation"));
new Pair<>("뉴욕은 미국에 있다.", "New York is in the United States."),
new Pair<>("서 있다", "to be standing"),
new Pair<>("그녀는 남자 친구가 있다.", "She has a boyfriend."));

for(int i = 0;i<examples.size();i++) {
String sentence = examples.get(i).first;
Expand All @@ -167,7 +171,7 @@ public void contents_areDisplayed() {
.check(matches(withText("Antonyms")));
onView(allOf(isDescendantOfA(withId(R.id.disp_antCard)),
withId(R.id.simpleCard_text)))
.check(matches(withText("오다, antonym two, antonym three")));
.check(matches(withText("덥다, antonym two, antonym three")));

// Synonyms
onView(withId(R.id.disp_synCard))
Expand All @@ -185,9 +189,9 @@ public void favorites_areDisplayed() {
.check(matches(withText("Conjugations")));

List<Pair<String, String>> favorites = Arrays.asList(
new Pair<>("Past", "갔어요"),
new Pair<>("Present", "가요"),
new Pair<>("Future", " 거예요"));
new Pair<>("Past", "추웠어요"),
new Pair<>("Present Honorific", "추우세요"),
new Pair<>("Future", "추울 거예요"));

// Verify favorite conjugations are shown
for(int i = 0;i<favorites.size();i++) {
Expand All @@ -210,8 +214,8 @@ public void favorites_goesToConjugations() {
onView(withText("SEE ALL")).perform(click());

intended(allOf(hasComponent(ConjugationActivity.class.getName()),
hasExtra(ConjugationActivity.EXTRA_STEM, "가다"),
hasExtra(ConjugationActivity.EXTRA_ISADJ, false),
hasExtra(ConjugationActivity.EXTRA_STEM, "춥다"),
hasExtra(ConjugationActivity.EXTRA_ISADJ, true),
hasExtra(ConjugationActivity.EXTRA_HONORIFIC, false),
hasExtra(ConjugationActivity.EXTRA_REGULAR, null)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import androidx.test.rule.ActivityTestRule;

import com.a494studios.koreanconjugator.MainActivity;
import com.a494studios.koreanconjugator.MockedResponses;
import com.a494studios.koreanconjugator.MockReader;
import com.a494studios.koreanconjugator.R;
import com.a494studios.koreanconjugator.display.DisplayActivity;
import com.a494studios.koreanconjugator.parsing.Server;
Expand Down Expand Up @@ -40,6 +40,7 @@
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withHint;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static com.a494studios.koreanconjugator.MockReader.readStringFromFile;
import static com.a494studios.koreanconjugator.Utils.testActionBar;
import static org.hamcrest.Matchers.allOf;

Expand All @@ -65,7 +66,7 @@ public void stubIntents() {
IdlingRegistry.getInstance().register(idler);

// Enqueue a response
serverRule.server.enqueue(new MockResponse().setBody(MockedResponses.WOD));
serverRule.server.enqueue(new MockResponse().setBody(readStringFromFile(MockReader.WOD)));

// Start test
activityRule.launchActivity(null);
Expand All @@ -91,7 +92,7 @@ public void wodCard_redirectsToDisplay() {
.perform(click());

intended(allOf(hasComponent(DisplayActivity.class.getName()),
hasExtra(DisplayActivity.EXTRA_ID, "가로0")));
hasExtra(DisplayActivity.EXTRA_ID, "속속들이0")));
}

@Test
Expand Down
Loading