I am new to unit test. I have a class which can make a chain call like .setUserName(...).setUserID(...).toJson How can I make the JUnit test about this?
public class Event{
private String userName;
private int userID;
private String userAddress;
public Event setUserName(String userName){
this.userName = userName;
return this;
}
public Event setUserID(String userID){
this.userID = userID;
return this;
}
public Event setUserAddress(String userAddress){
this.userAddress = userAddress;
return this;
}
public JSONObject toJson(){
JSONObject json = new JSONObject();
if(null != userName)
json.put("userName", userName);
if(0 != userID)
json.put("userID", userID);
if(null != userAddress)
json.put("userAddress", userAddress);
return json;
}
}
Do I need to test each of the set methods? something like
@Test
public void testSetUserName() {
Event event = new Event();
Assert.IsNotNull(event.setUserName("somename"));
}
I am not sure about that.