/**
* Tests for {@link ArrayOfString}.
*/
public void testArraysOfStrings() {
// This is our test subject.
final ArrayOfString array = Collections.arrayOfString();
// These are items to put in him.
final String[] items = new String[] {"zero goats", "one goat", "two goats"};
// Let's put the items in him.
for (int i = 0, n = items.length; i < n; ++i) {
array.push(items[i]);
}
// Are the items in the right places?
assertEquals(items.length, array.length());
for (int i = 0, n = items.length; i < n; ++i) {
assertEquals(items[i], array.get(i));
}
// These are some more items to put in him.
final String[] newItems = new String[] {"three goats", "four goats", "SQUIRREL!"};
// Put all these items in where the others were.
for (int i = 0, n = items.length; i < n; ++i) {
array.set(i, newItems[i]);
assertEquals(newItems[i], array.get(i));
}
// Shift our test subject to squeeze out the first item.
assertEquals(newItems[0], array.shift());
assertEquals(newItems.length - 1, array.length());
// Then Unshift.
array.unshift(newItems[0]);
assertEquals(newItems[0], array.get(0));
assertEquals(newItems.length, array.length());
// Now join them together in harmony.
assertEquals("three goats$four goats$SQUIRREL!", array.join("$"));
for (int i = 0, n = items.length; i < n; ++i) {
assertEquals(i, array.indexOf(newItems[i]));
assertTrue(array.contains(newItems[i]));
}
final String imposter = "Pajamas?";
assertEquals(-1, array.indexOf(imposter));
assertFalse(array.contains(imposter));
final String[] itemsA = new String[] {"atlanta", "eagle"};
final String[] itemsB = new String[] {"chaps", "profit"};
final ArrayOfString a = arrayFrom(itemsA);
final ArrayOfString b = arrayFrom(itemsB);
assertSamelitude(new String[] {itemsA[0], itemsA[1], itemsB[0], itemsB[1]}, a.concat(b));
assertSamelitude(itemsA, a);
assertSamelitude(itemsB, b);
}