I've setup a unit test for a Java application that calls a web service. This web service returns a JSON string. Let's assume the following samples
{
"id": 2,
"time": "1346",
"user": {
"firstname": "foo",
"lastname": "bar",
"email": "foo@bar.com"
}
}
class GetUserImpl implements GetUser {
public String getUserDetails() {
return new MyWebService().getUserDetaild(];
}
}
class Example Test {
@Test
public testGetUserDetails() {
assertEquals(new GetUserImpl().getUserDetails(), regex);
}
}
How would I use junit to test the following:
- Is the ID a number, I don't care what the value is as long as it's not null and equal to or greater than 0
- Is the time a valid format, regardless of the value
- Is the email a valid email format, regardless of the value