Using Content Assist

In this section you will use content assist to finish writing a new method. Open the file junit.samples/VectorTest.java in the Java editor if you do not already have it open and select the testSizeIsThree() method in the Outline view. If the file doesn't contain such a method see Adding new methods for instructions on how to add this method.

  1. Replace the TODO comment with the following lines.

    assertTrue(fFull.size() == 3);
    Vector v = new Vector();
    for (int i=0; i<3; i++)
      v.addElement(new Object());
    assert

  2. With your cursor at the end of the word assert, press Ctrl+Space to activate content assist. The content assist window with a list of proposals will appear. Scroll the list to see the available choices.

    Content assist

  3. With the content assist window still active, type the letter 't' in the source code after assert (with no space in between). The list is narrowed and only shows entries starting with 'assert'. Single-click various items in the list to view any available Javadoc help for each item.

    Content assist filtered

  4. Select assertTrue(boolean) from the list and press Enter. The code for the assertTrue(boolean) method is inserted.
  5. Complete the line so that it reads as follows:

    assertTrue(v.size() == fFull.size());

  6. Save the file.
Java editor
Java Content Assist
Java Editor Preferences