@@ -81,7 +81,7 @@ public void parseShouldExtractSeriesInfo() {
8181 parser .setImageUrlLocator ("#image-url" );
8282 parser .setSellerLocator ("#seller-info" );
8383 parser .setPriceLocator ("#price" );
84- parser .setCurrencyValue ( expectedCurrency );
84+ parser .setCurrencyLocator ( "#currency" );
8585
8686 SeriesInfo expectedInfo = new SeriesInfo ();
8787 expectedInfo .setCategoryName (expectedCategory );
@@ -102,6 +102,7 @@ public void parseShouldExtractSeriesInfo() {
102102 + "<a id='image-url' href='%s'>look at image</a>"
103103 + "<a id='seller-info' href='%s'>%s</a>"
104104 + "<p id='price'>%s</p>"
105+ + "<p id='currency'>%s</p>"
105106 + "</body>"
106107 + "</html" ,
107108 expectedCategory ,
@@ -110,7 +111,8 @@ public void parseShouldExtractSeriesInfo() {
110111 imageUrl ,
111112 expectedSellerUrl ,
112113 expectedSellerName ,
113- expectedPrice
114+ expectedPrice ,
115+ expectedCurrency
114116 );
115117
116118 SeriesInfo info = parser .parse (html );
@@ -135,6 +137,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
135137 String expectedSellerName = Random .sellerName ();
136138 String expectedSellerUrl = baseUri + sellerUrl ;
137139 String expectedPrice = Random .price ().toString ();
140+ String expectedCurrency = Random .currency ().toString ();
138141
139142 parser .setMatchedUrl (baseUri );
140143 parser .setCategoryLocator ("h1" );
@@ -143,6 +146,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
143146 parser .setImageUrlLocator ("a.image" );
144147 parser .setSellerLocator ("a.seller" );
145148 parser .setPriceLocator ("b" );
149+ parser .setCurrencyLocator ("div" );
146150
147151 SeriesInfo expectedInfo = new SeriesInfo ();
148152 expectedInfo .setCategoryName (expectedCategory );
@@ -152,6 +156,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
152156 expectedInfo .setSellerName (expectedSellerName );
153157 expectedInfo .setSellerUrl (expectedSellerUrl );
154158 expectedInfo .setPrice (expectedPrice );
159+ expectedInfo .setCurrency (expectedCurrency );
155160
156161 String html = String .format (
157162 "<html>"
@@ -162,12 +167,14 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
162167 + "<a class='image' href='%s'>look at image</a>"
163168 + "<a class='seller' href='%s'>%s</a>"
164169 + "<b>%s</b>"
170+ + "<div>%s</div>"
165171 + "<h1>ignored</h1>"
166172 + "<p>ignored</p>"
167173 + "<span>ignored</span>"
168174 + "<a class='image' href='none'>look at image</a>"
169175 + "<a class='seller' href='none'>seller name</a>"
170176 + "<b>ignored</b>"
177+ + "<div>ignored</div>"
171178 + "</body>"
172179 + "</html" ,
173180 expectedCategory ,
@@ -176,7 +183,8 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
176183 expectedImageUrl ,
177184 expectedSellerUrl ,
178185 expectedSellerName ,
179- expectedPrice
186+ expectedPrice ,
187+ expectedCurrency
180188 );
181189
182190 SeriesInfo info = parser .parse (html );
@@ -645,20 +653,39 @@ public void extractPriceShouldIgnoreTextOfChildrenTags() {
645653 //
646654
647655 @ Test
648- public void extractCurrencyShouldReturnNullWhenCurrencyValueIsNotSet () {
656+ public void extractCurrencyShouldReturnNullWhenCurrencyValuesAreNotSet () {
649657 parser .setCurrencyValue (null );
658+ parser .setCurrencyLocator (null );
650659
651660 String currency = parser .extractCurrency (null );
652661
653662 assertThat (currency ).isNull ();
654663 }
655664
665+ @ Test
666+ public void extractCurrencyShouldReturnValueOfCurrencyLocator () {
667+ String expectedValue = "CZK" ;
668+
669+ parser .setCurrencyLocator ("#currency" );
670+ parser .setCurrencyValue ("RUB" );
671+
672+ String html = String .format ("<span id='currency'>%s</span>" , expectedValue );
673+ Element doc = createDocumentFromText (html );
674+
675+ String currency = parser .extractCurrency (doc );
676+
677+ assertThat (currency ).as ("couldn't extract currency from '%s'" , doc )
678+ .isEqualTo (expectedValue );
679+ }
680+
656681 @ Test
657682 public void extractCurrencyShouldReturnCurrencyValue () {
658683 String expectedCurrency = Random .currency ().toString ();
659684 parser .setCurrencyValue (expectedCurrency );
685+ parser .setCurrencyLocator (Random .jsoupLocator ());
686+ Element doc = createEmptyDocument ();
660687
661- String currency = parser .extractCurrency (null );
688+ String currency = parser .extractCurrency (doc );
662689
663690 assertThat (currency ).isEqualTo (expectedCurrency );
664691 }
0 commit comments