Unit Testing Android function

Kyril Khaltesky

I want to unit test a function within my code, but when I try to input a ArrayList into it it gives me array initializer not allowed here

here is my code:

public class CreateActivityTest {

ArrayList<String> items;

public String Add(String item, ArrayList<String> items) {
    if (items.contains(item.toLowerCase().trim())) {
        return null;
    }
    else if (item == null || item.trim().equals("")) {
        return null;
    } else {
        return item.toLowerCase().replaceAll("\\s+", "");
    }
}

@Test
public void addTest () throws Exception {
    items = {"strawberry", "raspberry"};
    String input = Add("Strawberry ", items);
    String expected = null;
    assertEquals(input, expected);
}

}
nyarian
items = Arrays.asList("strawberry", "raspberry");

Or, if you want exactly arraylist, just

items = new ArrayList<>();
items.add("strawberry");
items.add("raspberry");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related