@@ -345,6 +345,60 @@ public void extractCategoryShouldReturnTextOfShortDescriptionLocator() {
345
345
assertThat (msg , category , equalTo (expectedName ));
346
346
}
347
347
348
+ //
349
+ // Tests for extractCountry()
350
+ //
351
+
352
+ @ Test
353
+ public void extractCountryShouldReturnNullWhenLocatorsAreNotSet () {
354
+ parser .setCountryLocator (null );
355
+ parser .setShortDescriptionLocator (null );
356
+ Element doc = createEmptyDocument ();
357
+
358
+ String country = parser .extractCountry (doc );
359
+
360
+ assertThat (country , is (nullValue ()));
361
+ }
362
+
363
+ @ Test
364
+ public void extractCountryShouldReturnNullWhenElementNotFound () {
365
+ parser .setCountryLocator (Random .jsoupLocator ());
366
+ Element doc = createEmptyDocument ();
367
+
368
+ String country = parser .extractCountry (doc );
369
+
370
+ assertThat (country , is (nullValue ()));
371
+ }
372
+
373
+ @ Test
374
+ public void extractCountryShouldReturnTextOfCountryLocator () {
375
+ parser .setCountryLocator ("#country" );
376
+
377
+ String expectedName = Random .countryName ();
378
+ String html = String .format ("<div id='country'>%s</div>" , expectedName );
379
+ Element doc = createDocumentFromText (html );
380
+
381
+ String country = parser .extractCountry (doc );
382
+
383
+ String msg = String .format ("couldn't extract a country from '%s'" , doc );
384
+ assertThat (msg , country , equalTo (expectedName ));
385
+ }
386
+
387
+ @ Test
388
+ public void extractCountryShouldReturnTextOfShortDescriptionLocator () {
389
+ parser .setCountryLocator (null );
390
+ parser .setShortDescriptionLocator ("#desc" );
391
+
392
+ String expectedName = Random .countryName ();
393
+ String html = String .format ("<div id='desc'>%s</div>" , expectedName );
394
+ Element doc = createDocumentFromText (html );
395
+
396
+ String country = parser .extractCountry (doc );
397
+
398
+ String msg = String .format ("couldn't extract a country from '%s'" , doc );
399
+ assertThat (msg , country , equalTo (expectedName ));
400
+ }
401
+
348
402
private static String describe (SiteParser parser ) {
349
403
StringBuilder sb = new StringBuilder ();
350
404
sb .append ("SiteParser[name=" )
0 commit comments