Question: I have the following tests to add users to a list:

```
@Test
public void testTheSizeOfUserListAfterAddingThreeUsers() {
    User james = new User(001, "JamesBond", "JB007", "Admin");
    User billy = new User(002, "BillyBob", "WOOHOONASCAR", null);
    User jane = new User(003, "CaliGurl88", "surfboardz", null);
    manager.addUser(james);
    manager.addUser(billy);
    manager.addUser(jane);
    assertEquals(3, manager.getSize());
    manager.removeUser(james);
    manager.removeUser(billy);
    manager.removeUser(jane);
}

```

However, I have to remove each user after each test, in order to start fresh for the next test.

Is there anyway I can use the `@After` annotation to remove all users created for each test? Maybe using a for loop?

Answer: 
Store the test objects in a List, then remove later:

```
public class TestClass{

    private List<User> createdUsers = new ArrayList<>();

    private Manager manager; //instantiate

    @Before
    public void setupUsers(){
        User james = new User(001, "JamesBond", "JB007", "Admin");
        User billy = new User(002, "BillyBob", "WOOHOONASCAR", null);    
        User jane = new User(003, "CaliGurl88", "surfboardz", null);
        createdUsers.add(james);
        createdUsers.add(billy);
        createdUsers.add(jane);
    }

    @After
    public void cleanUsers(){
        for(User createdUser : createdUsers){
            manager.removeUser(createdUser); //but if you test the behaviour of manager, then remove the created instances independently from manager
        }
        createdUsers.clear();
    }
}

```
The `@After` annotation is used with a method that will execute after each test. In this method, you can do whatever you want to clean your test environment.

```
@After
public void cleanup() {
    // Cleaning code goes here
}

```

You can use the name you want as your method name.

You can save the User instances in a `List<User>`, property of your test class, and then remove them in the `@After` method. Don't forget to remove users from your `List` once you've removed them from the `manager` list.

```
public class MyTestClass {

private List<User> users = new ArrayList<User>();

@Test
public void testTheSizeOfUserListAfterAddingThreeUsers() {
    User james = new User(001, "JamesBond", "JB007", "Admin");
    User billy = new User(002, "BillyBob", "WOOHOONASCAR", null);
    User jane = new User(003, "CaliGurl88", "surfboardz", null);
    manager.addUser(james);
    manager.addUser(billy);
    manager.addUser(jane);
    users.add(james);
    users.add(billy);
    users.add(jane);
    assertEquals(3, manager.getSize());
}

@After
public void cleanup() {
    for (User user : users) {
        manager.removeUser(user);
    }
    users.clear();
}
}

```