Skip to content

Commit 5160d12

Browse files
committed
update test
1 parent d0da8b3 commit 5160d12

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/test/java/im/nll/data/extractor/ExtractorsTest.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,17 @@ public void before() {
3737

3838
@Test
3939
public void testGet() throws Exception {
40+
//use extract method to extract data
4041
String title = Extractors.on(baseHtml).extract(selector("a.title")).asString();
42+
//use with method to extend value extractor
4143
String followers = Extractors.on(baseHtml).extract(selector("div.followers")).with(regex("\\d+")).asString();
42-
String description = Extractors.on(baseHtml).extract(selector("div.description")).asString();
43-
Assert.assertEquals("fivesmallq", title);
44-
Assert.assertEquals("29671", followers);
45-
Assert.assertEquals("Talk is cheap. Show me the code.", description);
46-
}
47-
48-
@Test
49-
public void testGetWithFilter() throws Exception {
50-
String title = Extractors.on(baseHtml).extract(selector("a.title")).asString();
51-
String followers = Extractors.on(baseHtml).extract(selector("div.followers")).with(regex("\\d+")).asString();
52-
//use filter to process value
44+
//use filter method to process value
5345
String description = Extractors.on(baseHtml).extract(selector("div.description")).filter(value -> value.toLowerCase()).asString();
46+
String year = Extractors.on("<div> Talk is cheap. Show me the code. - Fri, 25 Aug 2000 </div>").extract(selector("div")).filter(value -> value.trim()).with(regex("20\\d{2}")).filter(value -> "from " + value).asString();
5447
Assert.assertEquals("fivesmallq", title);
5548
Assert.assertEquals("29671", followers);
5649
Assert.assertEquals("talk is cheap. show me the code.", description);
50+
Assert.assertEquals("from 2000", year);
5751
}
5852

5953
@Test

0 commit comments

Comments
 (0)