I have a user-snippet class as shown below:
public class User
{
private int userID;
private static int nextID = 99;
private String firstName;
private String lastName;
private String email;
private String password;
private String fullName;
public User()
{
}
public User(String firstName, String lastName, String email, String password)
{
userID = nextID + 1;
nextID++;
this.firstName = firstName;
this.lastName = lastName;
fullName = firstName + " " + lastName;
this.email = email;
this.password = password;
}
I want to provide users with a unique UserID that increases each time a user instance is created.
I tried to do this with a static int NextID to hold the user ID of the next object and increment it in the constructor after using it each time.
However, when I tried this, it messed up my unit tests, and some of them fail when I run all the tests, but they still pass when they run individually.
Does anyone know how I can achieve this without breaking my unit tests?