
package com.twitter;

import java.util.*;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
import com.twitter.*;

public class ExtractorTest extends TestCase {
  protected Extractor extractor;

  public static Test suite() {
    Class[] testClasses = { ReplyTest.class, MentionTest.class, HashtagTest.class };
    return new TestSuite(testClasses);
  }

  public void setUp() throws Exception {
    extractor = new Extractor();
  }

  /**
   * Tests for the extractReplyScreenname method
   */
  public static class ReplyTest extends ExtractorTest {
    public void testReplyAtTheStart() {
      String extracted = extractor.extractReplyScreenname("@user reply");
      assertEquals("Failed to extract reply at the start", "user", extracted);
    }

    public void testReplyWithLeadingSpace() {
      String extracted = extractor.extractReplyScreenname(" @user reply");
      assertEquals("Failed to extract reply with leading space", "user", extracted);
    }
  }

  /**
   * Tests for the extractMentionedScreennames method
   */
  public static class MentionTest extends ExtractorTest {
    public void testMentionAtTheBeginning() {
      List<String> extracted = extractor.extractMentionedScreennames("@user mention");
      assertList("Failed to extract mention at the beginning", new String[]{"user"}, extracted);
    }

    public void testMentionWithLeadingSpace() {
      List<String> extracted = extractor.extractMentionedScreennames(" @user mention");
      assertList("Failed to extract mention with leading space", new String[]{"user"}, extracted);
    }

    public void testMentionInMidText() {
      List<String> extracted = extractor.extractMentionedScreennames("mention @user here");
      assertList("Failed to extract mention in mid text", new String[]{"user"}, extracted);
    }

    public void testMultipleMentions() {
      List<String> extracted = extractor.extractMentionedScreennames("mention @user1 here and @user2 here");
      assertList("Failed to extract multiple mentioned users", new String[]{"user1", "user2"}, extracted);
    }
  }

   /**
   * Tests for the extractHashtags method
   */
  public static class HashtagTest extends ExtractorTest {
    public void testHashtagAtTheBeginning() {
      List<String> extracted = extractor.extractHashtags("#hashtag mention");
      assertList("Failed to extract hashtag at the beginning", new String[]{"hashtag"}, extracted);
    }

    public void testHashtagWithLeadingSpace() {
      List<String> extracted = extractor.extractHashtags(" #hashtag mention");
      assertList("Failed to extract hashtag with leading space", new String[]{"hashtag"}, extracted);
    }

    public void testHashtagInMidText() {
      List<String> extracted = extractor.extractHashtags("mention #hashtag here");
      assertList("Failed to extract hashtag in mid text", new String[]{"hashtag"}, extracted);
    }

    public void testMultipleHashtags() {
      List<String> extracted = extractor.extractHashtags("text #hashtag1 #hashtag2");
      assertList("Failed to extract multiple hashtags", new String[]{"hashtag1", "hashtag2"}, extracted);
    }
  }

  /**
   * Helper method for asserting that the List of extracted Strings match the expected values.
   *
   * @param message to display on failure
   * @param expected Array of Strings that were expected to be extracted
   * @param actual List of Strings that were extracted
   */
  protected void assertList(String message, String[] expected, List<String> actual) {
    List<String> expectedList = Arrays.asList(expected);
    if (expectedList.size() != actual.size()) {
      fail(message + "\n\nExpected list and extracted list are differnt sizes:\n" +
      "  Expected (" + expectedList.size() + "): " + expectedList + "\n" +
      "  Actual   (" + actual.size() + "): " + actual);
    } else {
      for (int i=0; i < expectedList.size(); i++) {
        assertEquals(expectedList.get(i), actual.get(i));
      }
    }
  }
}
@@ -351,12 +351,27 @@
 lass
+, UrlTest.class
  %7D;%0A
-
     
@@ -1075,23 +1075,38 @@
 eennames
+%7BWithIndicies%7D
  method
+s
 %0A   */%0A 
@@ -2127,32 +2127,601 @@
 xtracted);%0A    %7D
+%0A%0A    public void testMentionWithIndicies() %7B%0A      List%3CExtractor.Entity%3E extracted = extractor.extractMentionedScreennamesWithIndicies(%22 @user1 mention @user2 here @user3 %22);%0A      assertEquals(extracted.size(), 3);%0A      assertEquals(extracted.get(0).start.intValue(), 1);%0A      assertEquals(extracted.get(0).end.intValue(), 7);%0A      assertEquals(extracted.get(1).start.intValue(), 16);%0A      assertEquals(extracted.get(1).end.intValue(), 22);%0A      assertEquals(extracted.get(2).start.intValue(), 28);%0A      assertEquals(extracted.get(2).end.intValue(), 34);%0A    %7D
 %0A  %7D%0A%0A   /**%0A   
@@ -2787,23 +2787,19 @@
 c class 
-Hashtag
+Url
 Test ext
@@ -3748,32 +3748,489 @@
 ed);%0A    %7D%0A  %7D%0A%0A
+  public static class HashtagTest extends ExtractorTest %7B%0A   public void testUrlWithIndicies() %7B%0A      List%3CExtractor.Entity%3E extracted = extractor.extractURLsWithIndicies(%22 http://t.co url http://www.twitter.com %22);%0A      assertEquals(extracted.get(0).start.intValue(), 0);%0A      assertEquals(extracted.get(0).end.intValue(), 12);%0A      assertEquals(extracted.get(1).start.intValue(), 16);%0A      assertEquals(extracted.get(1).end.intValue(), 39);%0A   %7D%0A  %7D%0A
   /**%0A   * Helpe
@@ -5042,9 +5042,10 @@
   %7D%0A  %7D%0A
-
 %7D
+%0A

add test for indicies