This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
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
Patrick Huang
committed
Dec 9, 2012
1 parent
16af672
commit 5c3ecb0
Showing
2 changed files
with
106 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
67 changes: 67 additions & 0 deletions
67
zanata-war/src/test/java/org/zanata/webtrans/client/presenter/PathDocumentFilterTest.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,67 @@ | ||
package org.zanata.webtrans.client.presenter; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.common.TranslationStats; | ||
import org.zanata.webtrans.shared.model.DocumentId; | ||
import org.zanata.webtrans.shared.model.DocumentInfo; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
|
||
/** | ||
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a> | ||
*/ | ||
public class PathDocumentFilterTest | ||
{ | ||
private PathDocumentFilter filter; | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception | ||
{ | ||
filter = new PathDocumentFilter(); | ||
} | ||
|
||
private static DocumentInfo docInfo(String name, String path) | ||
{ | ||
return new DocumentInfo(new DocumentId(1L), name, path, LocaleId.EN_US, new TranslationStats()); | ||
} | ||
|
||
@Test | ||
public void testAcceptWithCaseInsensitiveAndNotExactMatch() throws Exception | ||
{ | ||
filter.setPattern("a,b b, c , , d"); | ||
|
||
assertThat(filter.accept(docInfo("a", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("b b", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("c", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("C", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("d", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("b", "/pot/")), Matchers.equalTo(false)); | ||
} | ||
|
||
@Test | ||
public void testAcceptWithCaseSensitiveAndNotExactMatch() throws Exception | ||
{ | ||
filter.setPattern("a").setCaseSensitive(true); | ||
|
||
assertThat(filter.accept(docInfo("a", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("A", "/pot/")), Matchers.equalTo(false)); | ||
} | ||
|
||
@Test | ||
public void testSetFullText() throws Exception | ||
{ | ||
filter.setPattern("/pot/a").setFullText(true); | ||
|
||
assertThat(filter.accept(docInfo("a", "/pot/")), Matchers.equalTo(true)); | ||
assertThat(filter.accept(docInfo("a", "")), Matchers.equalTo(false)); | ||
} | ||
|
||
@Test | ||
public void alwaysAcceptIfNoPattern() | ||
{ | ||
assertThat(filter.accept(docInfo("a", "/pot/")), Matchers.equalTo(true)); | ||
} | ||
} |