Here is the input to my function
"<div class=\"xbox\">TESTING<span class=\"newbox\"><a href=\"javascript:void(0);\" id=\"btnbox\">Use a new box</a></span></div><div class=\"cardnumber\">***-1111</div></div>"
When I do the below it never returns anything but -1
input.indexOf("cardnumber")
Any reason this isn't working? when I do an indexOf("div") it returns fine ... (help)
thanks guys (sorry for not posting the unit test earlier)
public Cart viewCart() {
ResponseAndCookies result = service.makeHttpRequestWithUrl("https://www.xbox.com/account/fakebox/");
String response = result.getResponse();
String availableCreditCard = "<div class=\"cardnumber\">***";
if (response.contains(availableCreditCard)) {
return parseJson.parseCartAndReturnObject(response);
}
return null;
}
public class XboxViewCartServiceTest {
@Test
public void verify_cart_works_with_valid_login() {
FakeXboxCartParseJson jsonParser = new FakeXboxCartParseJson();
XboxViewCartService sut = new XboxViewCartService(new FakeXboxViewCartHttpBase(), jsonParser);
Cart cart = sut.viewCart(null);
Assert.assertTrue(jsonParser.calledMethod);
}
class FakeXboxViewCartHttpBase extends XboxHttpService {
@Override
public ResponseAndCookies doHttpPostWithUrl(String url, ResponseAndCookies responseAndCookies, String json) {
ResponseAndCookies result = new ResponseAndCookies();
result.setResponse("<div class=\"xbox\">TESTING<span class=\"newbox\"><a href=\"javascript:void(0);\" id=\"btnbox\">Use a new box</a></span></div><div class=\"cardnumber\">***-1111</div></div>");
return result;
}
}
class FakeXboxCartParseJson extends XboxCartParseJson {
public boolean calledMethod = false;
@Override
public Cart parseCartAndReturnObject(String html) {
calledMethod = true;
return null;
}
}
}