package org.wikipedia.editing.richtext;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import org.wikipedia.page.PageActivity;

import java.util.List;

public class SyntaxHighlighterTest extends ActivityInstrumentationTestCase2<PageActivity> {
    private PageActivity activity;

    public SyntaxHighlighterTest() {
        super(PageActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        activity = getActivity();
    }

    public void testSyntaxHighlight() throws Exception {

        final String testStr = "foo {{template1}} bar {{template2}} baz";
        final int span1Start = 4;
        final int span1End = 17;
        final int span2Start = 22;
        final int span2End = 35;

        EditText editText = new EditText(activity);
        new SyntaxHighlighter(activity, editText,
                new SyntaxHighlighter.OnSyntaxHighlightListener() {
            @Override
            public void syntaxHighlightResults(List<SpanExtents> spanExtents) {
                assertEquals(spanExtents.size(), 2);
                assertEquals(spanExtents.get(0).getClass(), ColorSpanEx.class);
                assertEquals(spanExtents.get(0).getStart(), span1Start);
                assertEquals(spanExtents.get(0).getEnd(), span1End);
                assertEquals(spanExtents.get(1).getClass(), ColorSpanEx.class);
                assertEquals(spanExtents.get(1).getStart(), span2Start);
                assertEquals(spanExtents.get(1).getEnd(), span2End);
            }
        });

        editText.setText(testStr);
    }
}

@@ -49,20 +49,19 @@
 android.
-test
+app
 .Activit
@@ -65,271 +65,403 @@
 vity
-InstrumentationTestCase2;%0Aimport android.widget.EditText;%0A%0Aimport org.wikipedia.page.PageActivity;%0A%0Aimport java.util.List;%0A%0Apublic class SyntaxHighlighterTest extends ActivityInstrumentationTestCase2%3CPageActivity%3E %7B%0A    private PageActivity activity;%0A%0A    
+;%0Aimport android.support.annotation.NonNull;%0Aimport android.support.test.rule.ActivityTestRule;%0Aimport android.widget.EditText;%0A%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.wikipedia.page.PageActivity;%0A%0Aimport java.util.List;%0A%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0Aimport static org.hamcrest.Matchers.instanceOf;%0Aimport static org.hamcrest.Matchers.is;%0A%0A
 public 
+class 
 Synt
@@ -481,168 +481,132 @@
 Test
-()
  %7B%0A    
-    super(PageActivity.class);%0A    %7D%0A%0A    @Override%0A    protected void setUp() throws Exception %7B%0A        super.setUp();%0A        activity = get
+@Rule%0A    @NonNull%0A    public final ActivityTestRule%3CPageActivity%3E activityRule = new ActivityTestRule%3C%3E(Page
 Activity
 ();%0A
@@ -605,18 +605,27 @@
 vity
-(
+.class
 );%0A
+%0A
     
-%7D%0A
+@Test
 %0A   
@@ -930,24 +930,29 @@
 ditText(
-a
+getA
 ctivity
+()
 );%0A     
@@ -976,24 +976,29 @@
 lighter(
-a
+getA
 ctivity
+()
 , editTe
@@ -1185,38 +1185,36 @@
           assert
-Equals
+That
 (spanExtents.siz
@@ -1218,17 +1218,21 @@
 size(), 
-2
+is(2)
 );%0A     
@@ -1240,38 +1240,36 @@
           assert
-Equals
+That
 (spanExtents.get
@@ -1276,32 +1276,43 @@
 (0).getClass(), 
+instanceOf(
 ColorSpanEx.clas
@@ -1305,32 +1305,33 @@
 lorSpanEx.class)
+)
 ;%0A              
@@ -1330,38 +1330,36 @@
           assert
-Equals
+That
 (spanExtents.get
@@ -1370,24 +1370,27 @@
 getStart(), 
+is(
 span1Start);
@@ -1384,24 +1384,25 @@
 (span1Start)
+)
 ;%0A          
@@ -1405,38 +1405,36 @@
           assert
-Equals
+That
 (spanExtents.get
@@ -1443,24 +1443,27 @@
 ).getEnd(), 
+is(
 span1End);%0A 
@@ -1455,24 +1455,25 @@
 is(span1End)
+)
 ;%0A          
@@ -1476,38 +1476,36 @@
           assert
-Equals
+That
 (spanExtents.get
@@ -1520,16 +1520,27 @@
 lass(), 
+instanceOf(
 ColorSpa
@@ -1549,16 +1549,17 @@
 x.class)
+)
 ;%0A      
@@ -1566,38 +1566,36 @@
           assert
-Equals
+That
 (spanExtents.get
@@ -1606,24 +1606,27 @@
 getStart(), 
+is(
 span2Start);
@@ -1624,16 +1624,17 @@
 n2Start)
+)
 ;%0A      
@@ -1653,14 +1653,12 @@
 sert
-Equals
+That
 (spa
@@ -1683,16 +1683,19 @@
 tEnd(), 
+is(
 span2End
@@ -1695,16 +1695,17 @@
 pan2End)
+)
 ;%0A      
@@ -1765,11 +1765,98 @@
 );%0A    %7D
+%0A%0A    private Activity getActivity() %7B%0A        return activityRule.getActivity();%0A    %7D
 %0A%7D%0A

update SyntaxHighlighterTest to JUnit 4