This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0234b13
commit 2a18f00
Showing
5 changed files
with
251 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
app/src/androidTest/java/com/example/week9fm5cc5/AsciiInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.example.week9fm5cc5; | ||
|
||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewParent; | ||
|
||
import androidx.test.espresso.ViewInteraction; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import com.example.week9fm5cc5.helpers.GenerateAscii; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static androidx.test.espresso.action.ViewActions.pressImeActionButton; | ||
import static androidx.test.espresso.action.ViewActions.replaceText; | ||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4.class) | ||
public class AsciiInstrumentedTest { | ||
|
||
private GenerateAscii generateAscii = new GenerateAscii(); | ||
private ViewInteraction inputBox = onView(withId(R.id.inputBox)); | ||
private ViewInteraction generateAsciiButton = onView(withId(R.id.generateAscii)); | ||
private ViewInteraction resultText = onView(withId(R.id.resultText)); | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Test | ||
public void testEmptyStatement() { | ||
String inputString = ""; | ||
Integer sum = generateAscii.sum(inputString); | ||
|
||
generateAsciiButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Sum of ASCII = "+ sum.toString()))); | ||
} | ||
|
||
@Test | ||
public void testHello() { | ||
String inputString = "hello world"; | ||
Integer sum = generateAscii.sum(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
|
||
generateAsciiButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Sum of ASCII = "+ sum.toString()))); | ||
} | ||
|
||
@Test | ||
public void testCustomAlphabet() { | ||
String inputString = "çöəğşıü"; | ||
Integer sum = generateAscii.sum(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
|
||
generateAsciiButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Sum of ASCII = "+ sum.toString()))); | ||
} | ||
|
||
private static Matcher<View> childAtPosition( | ||
final Matcher<View> parentMatcher, final int position) { | ||
|
||
return new TypeSafeMatcher<View>() { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Child at position " + position + " in parent "); | ||
parentMatcher.describeTo(description); | ||
} | ||
|
||
@Override | ||
public boolean matchesSafely(View view) { | ||
ViewParent parent = view.getParent(); | ||
return parent instanceof ViewGroup && parentMatcher.matches(parent) | ||
&& view.equals(((ViewGroup) parent).getChildAt(position)); | ||
} | ||
}; | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
app/src/androidTest/java/com/example/week9fm5cc5/ReplaceCharactersInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.example.week9fm5cc5; | ||
|
||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewParent; | ||
|
||
import androidx.test.espresso.ViewInteraction; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import com.example.week9fm5cc5.helpers.ReplaceCharacters; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.click; | ||
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; | ||
import static androidx.test.espresso.action.ViewActions.pressImeActionButton; | ||
import static androidx.test.espresso.action.ViewActions.replaceText; | ||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4.class) | ||
public class ReplaceCharactersInstrumentedTest { | ||
|
||
private ReplaceCharacters replaceCharacters = new ReplaceCharacters(); | ||
private ViewInteraction inputBox = onView(withId(R.id.inputBox)); | ||
private ViewInteraction replaceCharactersButton = onView(withId(R.id.replaceCharacters)); | ||
private ViewInteraction resultText = onView(withId(R.id.resultText)); | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Test | ||
public void testEmptyStatement() { | ||
String inputString = ""; | ||
String result = replaceCharacters.generate(inputString); | ||
|
||
replaceCharactersButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Result = \"" + result + "\""))); | ||
} | ||
|
||
@Test | ||
public void testHelloWorld() { | ||
String inputString = "Hello World"; | ||
String result = replaceCharacters.generate(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
replaceCharactersButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Result = \"" + result + "\""))); | ||
} | ||
|
||
@Test | ||
public void testLongText() { | ||
String inputString = "In publishing and graphic design, Lorem ipsum is a placeholder text."; | ||
String result = replaceCharacters.generate(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
replaceCharactersButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Result = \"" + result + "\""))); | ||
} | ||
|
||
@Test | ||
public void testCustomAlphabet() { | ||
String inputString = "çöəğşıü"; | ||
String result = replaceCharacters.generate(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
replaceCharactersButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Result = \"" + result + "\""))); | ||
} | ||
|
||
@Test | ||
public void testWithNumbers() { | ||
String inputString = "0123456789"; | ||
String result = replaceCharacters.generate(inputString); | ||
|
||
inputBox.perform(click()); | ||
inputBox.perform(replaceText(inputString), closeSoftKeyboard()); | ||
inputBox.perform(pressImeActionButton()); | ||
replaceCharactersButton.perform(click()); | ||
|
||
resultText.check(matches(withText("Result = \"" + result + "\""))); | ||
} | ||
|
||
private static Matcher<View> childAtPosition( | ||
final Matcher<View> parentMatcher, final int position) { | ||
|
||
return new TypeSafeMatcher<View>() { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Child at position " + position + " in parent "); | ||
parentMatcher.describeTo(description); | ||
} | ||
|
||
@Override | ||
public boolean matchesSafely(View view) { | ||
ViewParent parent = view.getParent(); | ||
return parent instanceof ViewGroup && parentMatcher.matches(parent) | ||
&& view.equals(((ViewGroup) parent).getChildAt(position)); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters