Skip to content

Commit

Permalink
feat: add some test unit to code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio López committed Jan 21, 2022
1 parent 851c49a commit 4ba04b3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/test/java/io/github/ajclopez/mss/MongoSpringSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,29 @@ public void canUseRegexWithOptions() {

String query = "firstname=/JOHN/i";
Query mongoQuery = MongoSpringSearch.mss(query);

Pattern pattern = Pattern.compile("/JOHN/", Pattern.CASE_INSENSITIVE);

Document document = ((Document)mongoQuery.getQueryObject().get("$and", BasicDBList.class).get(0));

String expected = Pattern.compile(pattern.pattern().replace("/", ""), Pattern.CASE_INSENSITIVE).pattern();

Assert.assertEquals(expected, document.get("firstname").toString());
}

@Test
public void canUseRegexWithAllOptions() {

String query = "firstname=/JOHN/gmixs";
Query mongoQuery = MongoSpringSearch.mss(query);

Pattern pattern = Pattern.compile("/JOHN/", Pattern.CASE_INSENSITIVE);

System.out.println(mongoQuery);
Document document = ((Document)mongoQuery.getQueryObject().get("$and", BasicDBList.class).get(0));

String expected = Pattern.compile(pattern.pattern().replace("/", ""), Pattern.CASE_INSENSITIVE).pattern();

Assert.assertEquals(expected, document.get("firstname").toString());

}

Expand Down

0 comments on commit 4ba04b3

Please sign in to comment.