summaryrefslogtreecommitdiff
path: root/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java')
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java112
1 files changed, 54 insertions, 58 deletions
diff --git a/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java b/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java
index 3aafa7d..def820e 100644
--- a/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java
+++ b/library/test/robotest/src/com/android/setupwizardlib/span/LinkSpanTest.java
@@ -17,7 +17,6 @@
package com.android.setupwizardlib.span;
import static com.google.common.truth.Truth.assertThat;
-
import static org.junit.Assert.assertSame;
import static org.robolectric.RuntimeEnvironment.application;
@@ -27,82 +26,79 @@ import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
-
import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SuwLibRobolectricTestRunner.class)
public class LinkSpanTest {
- @Test
- public void onClick_shouldCallListenerOnContext() {
- final TestContext context = new TestContext(application);
- final TextView textView = new TextView(context);
- final LinkSpan linkSpan = new LinkSpan("test_id");
+ @Test
+ public void onClick_shouldCallListenerOnContext() {
+ final TestContext context = new TestContext(application);
+ final TextView textView = new TextView(context);
+ final LinkSpan linkSpan = new LinkSpan("test_id");
- linkSpan.onClick(textView);
+ linkSpan.onClick(textView);
- assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan);
- }
+ assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan);
+ }
- @Test
- public void onClick_contextDoesNotImplementOnClickListener_shouldBeNoOp() {
- final TextView textView = new TextView(application);
- final LinkSpan linkSpan = new LinkSpan("test_id");
+ @Test
+ public void onClick_contextDoesNotImplementOnClickListener_shouldBeNoOp() {
+ final TextView textView = new TextView(application);
+ final LinkSpan linkSpan = new LinkSpan("test_id");
- linkSpan.onClick(textView);
+ linkSpan.onClick(textView);
- // This would be no-op, because the context doesn't implement LinkSpan.OnClickListener.
- // Just check that no uncaught exception here.
- }
+ // This would be no-op, because the context doesn't implement LinkSpan.OnClickListener.
+ // Just check that no uncaught exception here.
+ }
- @Test
- public void onClick_contextWrapsOnClickListener_shouldCallWrappedListener() {
- final TestContext context = new TestContext(application);
- final Context wrapperContext = new ContextWrapper(context);
- final TextView textView = new TextView(wrapperContext);
- final LinkSpan linkSpan = new LinkSpan("test_id");
+ @Test
+ public void onClick_contextWrapsOnClickListener_shouldCallWrappedListener() {
+ final TestContext context = new TestContext(application);
+ final Context wrapperContext = new ContextWrapper(context);
+ final TextView textView = new TextView(wrapperContext);
+ final LinkSpan linkSpan = new LinkSpan("test_id");
+ linkSpan.onClick(textView);
+ assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan);
+ }
- linkSpan.onClick(textView);
- assertSame("Clicked LinkSpan should be passed to setup", linkSpan, context.clickedSpan);
- }
+ @Test
+ public void onClick_shouldClearSelection() {
+ final TestContext context = new TestContext(application);
+ final TextView textView = new TextView(context);
+ textView.setMovementMethod(LinkMovementMethod.getInstance());
+ textView.setFocusable(true);
+ textView.setFocusableInTouchMode(true);
+ final LinkSpan linkSpan = new LinkSpan("test_id");
- @Test
- public void onClick_shouldClearSelection() {
- final TestContext context = new TestContext(application);
- final TextView textView = new TextView(context);
- textView.setMovementMethod(LinkMovementMethod.getInstance());
- textView.setFocusable(true);
- textView.setFocusableInTouchMode(true);
- final LinkSpan linkSpan = new LinkSpan("test_id");
-
- SpannableStringBuilder text = new SpannableStringBuilder("Lorem ipsum dolor sit");
- textView.setText(text);
- text.setSpan(linkSpan, /* start= */ 0, /* end= */ 5, /* flags= */ 0);
- // Simulate the touch effect set by TextView when touched.
- Selection.setSelection(text, /* start= */ 0, /* end= */ 5);
-
- linkSpan.onClick(textView);
-
- assertThat(Selection.getSelectionStart(textView.getText())).isEqualTo(0);
- assertThat(Selection.getSelectionEnd(textView.getText())).isEqualTo(0);
- }
+ SpannableStringBuilder text = new SpannableStringBuilder("Lorem ipsum dolor sit");
+ textView.setText(text);
+ text.setSpan(linkSpan, /* start= */ 0, /* end= */ 5, /* flags= */ 0);
+ // Simulate the touch effect set by TextView when touched.
+ Selection.setSelection(text, /* start= */ 0, /* stop= */ 5);
+
+ linkSpan.onClick(textView);
- @SuppressWarnings("deprecation")
- private static class TestContext extends ContextWrapper implements LinkSpan.OnClickListener {
+ assertThat(Selection.getSelectionStart(textView.getText())).isEqualTo(0);
+ assertThat(Selection.getSelectionEnd(textView.getText())).isEqualTo(0);
+ }
- public LinkSpan clickedSpan = null;
+ @SuppressWarnings("deprecation")
+ private static class TestContext extends ContextWrapper implements LinkSpan.OnClickListener {
- TestContext(Context base) {
- super(base);
- }
+ public LinkSpan clickedSpan = null;
+
+ TestContext(Context base) {
+ super(base);
+ }
- @Override
- public void onClick(LinkSpan span) {
- clickedSpan = span;
- }
+ @Override
+ public void onClick(LinkSpan span) {
+ clickedSpan = span;
}
+ }
}