@@ -81,7 +81,7 @@ public void parseShouldExtractSeriesInfo() {
81
81
parser .setImageUrlLocator ("#image-url" );
82
82
parser .setSellerLocator ("#seller-info" );
83
83
parser .setPriceLocator ("#price" );
84
- parser .setCurrencyValue ( expectedCurrency );
84
+ parser .setCurrencyLocator ( "#currency" );
85
85
86
86
SeriesInfo expectedInfo = new SeriesInfo ();
87
87
expectedInfo .setCategoryName (expectedCategory );
@@ -102,6 +102,7 @@ public void parseShouldExtractSeriesInfo() {
102
102
+ "<a id='image-url' href='%s'>look at image</a>"
103
103
+ "<a id='seller-info' href='%s'>%s</a>"
104
104
+ "<p id='price'>%s</p>"
105
+ + "<p id='currency'>%s</p>"
105
106
+ "</body>"
106
107
+ "</html" ,
107
108
expectedCategory ,
@@ -110,7 +111,8 @@ public void parseShouldExtractSeriesInfo() {
110
111
imageUrl ,
111
112
expectedSellerUrl ,
112
113
expectedSellerName ,
113
- expectedPrice
114
+ expectedPrice ,
115
+ expectedCurrency
114
116
);
115
117
116
118
SeriesInfo info = parser .parse (html );
@@ -135,6 +137,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
135
137
String expectedSellerName = Random .sellerName ();
136
138
String expectedSellerUrl = baseUri + sellerUrl ;
137
139
String expectedPrice = Random .price ().toString ();
140
+ String expectedCurrency = Random .currency ().toString ();
138
141
139
142
parser .setMatchedUrl (baseUri );
140
143
parser .setCategoryLocator ("h1" );
@@ -143,6 +146,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
143
146
parser .setImageUrlLocator ("a.image" );
144
147
parser .setSellerLocator ("a.seller" );
145
148
parser .setPriceLocator ("b" );
149
+ parser .setCurrencyLocator ("div" );
146
150
147
151
SeriesInfo expectedInfo = new SeriesInfo ();
148
152
expectedInfo .setCategoryName (expectedCategory );
@@ -152,6 +156,7 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
152
156
expectedInfo .setSellerName (expectedSellerName );
153
157
expectedInfo .setSellerUrl (expectedSellerUrl );
154
158
expectedInfo .setPrice (expectedPrice );
159
+ expectedInfo .setCurrency (expectedCurrency );
155
160
156
161
String html = String .format (
157
162
"<html>"
@@ -162,12 +167,14 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
162
167
+ "<a class='image' href='%s'>look at image</a>"
163
168
+ "<a class='seller' href='%s'>%s</a>"
164
169
+ "<b>%s</b>"
170
+ + "<div>%s</div>"
165
171
+ "<h1>ignored</h1>"
166
172
+ "<p>ignored</p>"
167
173
+ "<span>ignored</span>"
168
174
+ "<a class='image' href='none'>look at image</a>"
169
175
+ "<a class='seller' href='none'>seller name</a>"
170
176
+ "<b>ignored</b>"
177
+ + "<div>ignored</div>"
171
178
+ "</body>"
172
179
+ "</html" ,
173
180
expectedCategory ,
@@ -176,7 +183,8 @@ public void parseShouldExtractSeriesInfoFromFirstMatchedElements() {
176
183
expectedImageUrl ,
177
184
expectedSellerUrl ,
178
185
expectedSellerName ,
179
- expectedPrice
186
+ expectedPrice ,
187
+ expectedCurrency
180
188
);
181
189
182
190
SeriesInfo info = parser .parse (html );
@@ -645,20 +653,39 @@ public void extractPriceShouldIgnoreTextOfChildrenTags() {
645
653
//
646
654
647
655
@ Test
648
- public void extractCurrencyShouldReturnNullWhenCurrencyValueIsNotSet () {
656
+ public void extractCurrencyShouldReturnNullWhenCurrencyValuesAreNotSet () {
649
657
parser .setCurrencyValue (null );
658
+ parser .setCurrencyLocator (null );
650
659
651
660
String currency = parser .extractCurrency (null );
652
661
653
662
assertThat (currency ).isNull ();
654
663
}
655
664
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
+
656
681
@ Test
657
682
public void extractCurrencyShouldReturnCurrencyValue () {
658
683
String expectedCurrency = Random .currency ().toString ();
659
684
parser .setCurrencyValue (expectedCurrency );
685
+ parser .setCurrencyLocator (Random .jsoupLocator ());
686
+ Element doc = createEmptyDocument ();
660
687
661
- String currency = parser .extractCurrency (null );
688
+ String currency = parser .extractCurrency (doc );
662
689
663
690
assertThat (currency ).isEqualTo (expectedCurrency );
664
691
}
0 commit comments