use of org.languagetool.rules.CategoryId in project languagetool by languagetool-org.
the class InputSentenceTest method test.
@Test
public void test() {
Language lang = Languages.getLanguageForShortCode("xx-XX");
InputSentence inputSentence1a = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))));
InputSentence inputSentence1b = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))));
assertEquals(inputSentence1a, inputSentence1b);
InputSentence inputSentence2 = new InputSentence("foo", lang, null, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))));
assertNotEquals(inputSentence1a, inputSentence2);
assertNotEquals(inputSentence1b, inputSentence2);
}
use of org.languagetool.rules.CategoryId in project languagetool by languagetool-org.
the class MatchDatabaseTest method test.
@Test
public void test() throws SQLException, ClassNotFoundException {
Language language = Languages.getLanguageForShortCode("de");
MatchDatabase database = new MatchDatabase("jdbc:derby:atomFeedChecksDB;create=true", "user", "pass");
database.dropTables();
database.createTables();
assertThat(database.getLatestDate(language), is(new Date(0)));
assertThat(database.list().size(), is(0));
assertThat(database.getCheckDates().size(), is(0));
FakeRule rule1 = new FakeRule(1);
rule1.setCategory(new Category(new CategoryId("TEST_ID"), "My Category"));
RuleMatch ruleMatch = new RuleMatch(rule1, 5, 10, "my message");
AtomFeedItem feedItem1 = new AtomFeedItem("//id1?diff=123", "title", "summary1", new Date(10000));
WikipediaRuleMatch wikiRuleMatch1 = new WikipediaRuleMatch(language, ruleMatch, "my context", feedItem1);
database.add(wikiRuleMatch1);
assertThat(database.list().size(), is(1));
assertThat(database.list().get(0).getRuleId(), is("ID_1"));
assertThat(database.list().get(0).getRuleDescription(), is("A fake rule"));
assertThat(database.list().get(0).getRuleMessage(), is("my message"));
assertThat(database.list().get(0).getTitle(), is("title"));
assertThat(database.list().get(0).getErrorContext(), is("my context"));
assertThat(database.list().get(0).getDiffId(), is(123L));
assertThat(database.list().get(0).getFixDiffId(), is(0L));
assertThat(database.list().get(0).getEditDate(), is(new Date(10000)));
assertThat(database.getLatestDate(language), is(new Date(0)));
assertNull(database.list().get(0).getRuleSubId());
assertNull(database.list().get(0).getFixDate());
assertThat(database.getCheckDates().size(), is(0));
// same ID, different character positions
RuleMatch ruleMatch2 = new RuleMatch(new FakeRule(1), 9, 11, "my message");
AtomFeedItem feedItem2 = new AtomFeedItem("//id2?diff=124", "title", "summary2", new Date(9000000000L));
WikipediaRuleMatch wikiRuleMatch2 = new WikipediaRuleMatch(language, ruleMatch2, "my context", feedItem2);
int affected = database.markedFixed(wikiRuleMatch2);
assertThat(affected, is(1));
assertThat(database.list().get(0).getFixDate(), is(new Date(9000000000L)));
assertThat(database.list().get(0).getDiffId(), is(123L));
assertThat(database.list().get(0).getFixDiffId(), is(124L));
assertThat(database.getLatestDate(language), is(new Date(0)));
assertThat(database.getCheckDates().size(), is(0));
}
Aggregations