public void login(String username, String password) {
for(int i = 0; i < Users.size(); i++) {
user users = (user) Users.get(i);
if(users.getUsername().contains(username)
&& users.getPassword().contains(password)) {
userName = users.getUsername();
userLevel = users.getUserLevel();
isSuccess = true;
}
}
}
Hello everyone. I'm trying to do a java unit testing for this method using Java Junit. But i don't know how to do that? Because there's a for loop.
Let me explain the method.
for(int i=0;i<Users.size();i++){
This "Users" is a vector. This loop runs unit this vector ends.
user users = (user) Users.get(i);
Then im calling user class for user instance.
if((users.getUsername().contains(username)) &&
(users.getPassword().contains(password))) {
Then if any of the users that matches with the values in the vectors, this gives the output.
Can anyone tell me how to write a unit test for this?