In this section you will use content assist to fill in a template for a common loop structure. Open junit.samples/VectorTest.java file in the Java editor if you do not already have it open.
public void testValues() {
Integer[] expected= new Integer[3];
for
for
, press Ctrl+Space to enable content assist.
You will see a list of common templates for "for" loops.
When you single-click a template, or select it with the Up or Down
arrow keys, you'll see the code for the template in
its help message. Note that the local array name is guessed automatically.
for - iterate over array
entry and press Enter to confirm the template.
The template will be inserted in your source code.
for
loop as follows:
for (int e= 0; e < expected.length; e++) {
expected[e]= new Integer(e + 1);
}
Integer[] actual= to
to
, press Ctrl+Space to enable content assist. Pick toarray - convert collection to array
and press Enter to confirm the selection (or double-click the
selection).
type
is highlighted and selected.
Integer
. The type of array constructor changes
when you change the selection.
collection
and
overwrite it by typing fFull
.
assertEquals(expected.length, actual.length);
for (int i= 0; i < actual.length; i++)
assertEquals(expected[i], actual[i]);