import static org.junit.Assert.assertEquals;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.sps.data.SearchQuery;
import java.util.Arrays;
import java.util.List;
import java.net.MalformedURLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.junit.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

public class FiltersTest {
    @Test
    public void GeneralFilterTest1() throws MalformedURLException{
        String mockTitle = "MOCK_TITLE https:// hello hi how$ a4e/you";
        String mockDescription = "MOCK_DESCRIPTION this-% is A  \n^description";
        List<String> keywordsList = Arrays.asList((mockTitle + " " + mockDescription).toLowerCase().split("\\s+"));
        String query = SearchQuery.filterKeywords(keywordsList, 7);
        // No special characters.
        Pattern pattern = Pattern.compile("[^a-zA-Z0-9 ]");
        Matcher matcher = pattern.matcher(query);
        assertEquals(matcher.find(), false);
        // URL removed.
        assertEquals(query.indexOf("https://"), -1);
        // Filtering again without a size limit shouldn't change the query.
        String filteredQuery = SearchQuery.filterKeywords(Arrays.asList(query.split("\\s+")), 1000);
        assertEquals(query, filteredQuery);
    }

    @Test
    public void GeneralFilterTest2() throws MalformedURLException{
        String mockTitle = "MOCK TITLE test/test$ test hello.";
        String mockDescription = "MOCK DESCRIPTION $$$ c4$h m0nEy/";
        List<String> keywordsList = Arrays.asList((mockTitle + mockDescription).toLowerCase().split("\\s+"));
        String query = SearchQuery.filterKeywords(keywordsList, 7);
        // No special characters.
        Pattern pattern = Pattern.compile("[^a-zA-Z0-9 ]");
        Matcher matcher = pattern.matcher(query);
        assertEquals(matcher.find(), false);
        // Filtering again without a size limit shouldn't change the query.
        String filteredQuery = SearchQuery.filterKeywords(Arrays.asList(query.split("\\s+")), 1000);
        assertEquals(query, filteredQuery);
    }

    @Test
    public void LengthTest() {
        String mockTitle = "MOCK_asdfasdfasdfasdfjgjafjfjwefjsdfjsdfjasdfjdsfjsdfasdfdfasdfsadf";
        String mockDescription = "mock description";
        List<String> keywordsList = Arrays.asList((mockTitle + " " + mockDescription).toLowerCase().split("\\s+"));
        String query = SearchQuery.filterKeywords(keywordsList, 7);
        // Long string should be removed.
        assertEquals(query, "mock description");
    }

    @Test
    public void DuplicateTest() {
        String mockTitle = "mock mock mock mock mock mock";
        String mockDescription = "mock mock mock mock mock mock mock";
        List<String> keywordsList = Arrays.asList((mockTitle + " " + mockDescription).toLowerCase().split("\\s+"));
        String query = SearchQuery.filterKeywords(keywordsList, 7);
        // Duplicates should be removed.
        assertEquals(query, "mock");
    }
}
@@ -577,17 +577,16 @@
 lterTest
-1
 () throw
@@ -1442,87 +1442,54 @@
     
-%7D%0A%0A
     
-@Test%0A    public void GeneralFilterTest2() throws MalformedURLExce
+// Try with another title and descri
 ption
-%7B
+.
 %0A   
@@ -1485,39 +1485,32 @@
 iption.%0A        
-String 
 mockTitle = %22MOC
@@ -1542,39 +1542,32 @@
 ello.%22;%0A        
-String 
 mockDescription 
@@ -1607,37 +1607,24 @@
 y/%22;%0A       
- List%3CString%3E
  keywordsLis
@@ -1701,39 +1701,32 @@
 %5Cs+%22));%0A        
-String 
 query = SearchQu
@@ -1807,76 +1807,8 @@
     
- 
-Pattern pattern = Pattern.compile(%22%5B%5Ea-zA-Z0-9 %5D%22);%0A        Matcher
  mat
@@ -1959,39 +1959,32 @@
  query.%0A        
-String 
 filteredQuery = 
@@ -3020,10 +3020,1251 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void EmptyTitle() %7B%0A        String mockTitle = %22%22;%0A        String mockDescription = %22mock description te$t%22;%0A        List%3CString%3E keywordsList = Arrays.asList((mockTitle + %22 %22 + mockDescription).toLowerCase().split(%22%5C%5Cs+%22));%0A        String query = SearchQuery.filterKeywords(keywordsList, 7);%0A        // Query should be from description only.%0A        assertEquals(query, %22mock description%22);%0A    %7D%0A%0A    @Test%0A    public void EmptyDescription() %7B%0A        String mockTitle = %22mock title h$llo%22;%0A        String mockDescription = %22%22;%0A        List%3CString%3E keywordsList = Arrays.asList((mockTitle + %22 %22 + mockDescription).toLowerCase().split(%22%5C%5Cs+%22));%0A        String query = SearchQuery.filterKeywords(keywordsList, 7);%0A        // Query should be from title only.%0A        assertEquals(query, %22mock title%22);%0A    %7D%0A%0A    @Test%0A    public void AllEmpty() %7B%0A        String mockTitle = %22%22;%0A        String mockDescription = %22%22;%0A        // This yields an empty keywords list.%0A        List%3CString%3E keywordsList = Arrays.asList((mockTitle + %22 %22 + mockDescription).toLowerCase().split(%22%5C%5Cs+%22));%0A        String query = SearchQuery.filterKeywords(keywordsList, 7);%0A        // Query should be empty.%0A        assertEquals(query, %22%22);%0A    %7D
 %0A%7D

Address more pull request suggestions