@@ -292,6 +292,101 @@ public void parseShouldRequireNonBlankPageContent() {
292
292
parser .parse (nullOrBlank ());
293
293
}
294
294
295
+ @ Test
296
+ public void parseShouldExtractSeriesInfo () {
297
+ String baseUri = "http://base.uri" ;
298
+ String expectedCategory = Random .categoryName ();
299
+ String expectedCountry = Random .countryName ();
300
+ String expectedIssueDate = Random .issueYear ().toString ();
301
+ String imageUrl = String .format (
302
+ "/%s-%s-%s.png" ,
303
+ expectedCountry .toLowerCase (),
304
+ expectedCategory .toLowerCase (),
305
+ expectedIssueDate
306
+ );
307
+ String expectedImageUrl = baseUri + imageUrl ;
308
+
309
+ parser .setMatchedUrl (baseUri );
310
+ parser .setCategoryLocator ("#category-name" );
311
+ parser .setCountryLocator ("#country-name" );
312
+ parser .setIssueDateLocator ("#issue-date" );
313
+ parser .setImageUrlLocator ("#image-url" );
314
+
315
+ SeriesInfo expectedInfo = new SeriesInfo ();
316
+ expectedInfo .setCategoryName (expectedCategory );
317
+ expectedInfo .setCountryName (expectedCountry );
318
+ expectedInfo .setIssueDate (expectedIssueDate );
319
+ expectedInfo .setImageUrl (expectedImageUrl );
320
+
321
+ String html = String .format (
322
+ "<html>"
323
+ + "<body>"
324
+ + "<p id='category-name'>%s</p>"
325
+ + "<p id='country-name'>%s</p>"
326
+ + "<p id='issue-date'>%s</p>"
327
+ + "<a id='image-url' href='%s'>look at image</a>"
328
+ + "</body>"
329
+ + "</html" ,
330
+ expectedCategory ,
331
+ expectedCountry ,
332
+ expectedIssueDate ,
333
+ imageUrl
334
+ );
335
+
336
+ SeriesInfo info = parser .parse (html );
337
+
338
+ assertThat (info , is (equalTo (expectedInfo )));
339
+ }
340
+ @ Test
341
+ public void parseShouldExtractSeriesInfoFromFirstMatchedElements () {
342
+ String baseUri = "http://base.uri" ;
343
+ String expectedCategory = Random .categoryName ();
344
+ String expectedCountry = Random .countryName ();
345
+ String expectedIssueDate = Random .issueYear ().toString ();
346
+ String imageUrl = String .format (
347
+ "/%s-%s-%s.png" ,
348
+ expectedCountry .toLowerCase (),
349
+ expectedCategory .toLowerCase (),
350
+ expectedIssueDate
351
+ );
352
+ String expectedImageUrl = baseUri + imageUrl ;
353
+
354
+ parser .setMatchedUrl (baseUri );
355
+ parser .setCategoryLocator ("h1" );
356
+ parser .setCountryLocator ("p" );
357
+ parser .setIssueDateLocator ("span" );
358
+ parser .setImageUrlLocator ("a" );
359
+
360
+ SeriesInfo expectedInfo = new SeriesInfo ();
361
+ expectedInfo .setCategoryName (expectedCategory );
362
+ expectedInfo .setCountryName (expectedCountry );
363
+ expectedInfo .setIssueDate (expectedIssueDate );
364
+ expectedInfo .setImageUrl (expectedImageUrl );
365
+
366
+ String html = String .format (
367
+ "<html>"
368
+ + "<body>"
369
+ + "<h1>%s</h1>"
370
+ + "<p>%s</p>"
371
+ + "<span>%s</span>"
372
+ + "<a href='%s'>look at image</a>"
373
+ + "<h1>ignored</h1>"
374
+ + "<p>ignored</p>"
375
+ + "<span>ignored</span>"
376
+ + "<a href='none'>look at image</a>"
377
+ + "</body>"
378
+ + "</html" ,
379
+ expectedCategory ,
380
+ expectedCountry ,
381
+ expectedIssueDate ,
382
+ expectedImageUrl
383
+ );
384
+
385
+ SeriesInfo info = parser .parse (html );
386
+
387
+ assertThat (info , is (equalTo (expectedInfo )));
388
+ }
389
+
295
390
//
296
391
// Tests for toString()
297
392
//
0 commit comments