In this section, you will edit Java elements in the workbench.
public void testSizeIsThree() {
assertTrue(fFull.size() == 3); }
In this section, you will use the local history feature to switch to a previously saved version of an individual Java element.
public void testSizeIsThree() {
fFull.add(0, new Integer(0));
fFull.remove(new Integer(3));
assertTrue(fFull.size() == 3); }
testSizeIsThree()
, and from its context menu, select Replace
With > Element from Local History.
In this section you will use content assist to help finish writing a new
method. Open junit.samples.VectorTest.java file in the Java
editor if you do not already have it open and select the testSizeIsThree()
method
in the Outline view.
Vector v = new Vector();
for (int i=0; i<3; i++)
v.addElement(new Object());
assert
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.
assert
(with no space in between). The list is narrowed and only shows entries
starting with 'assertt'. Select and then hover over various items in the list to view any available Javadoc help for each item.
assertTrue(boolean)
from the list and press Enter. The code for the assertTrue(boolean)
method is inserted.
assertTrue(v.size() == fFull.size());
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
, type Ctrl+Space to enable content assist.
You will see a list of common templates for "for" loops.
When you hover over a template, you'll see the code for the template in
its help. 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 i= 0; i < expected.length; i++) {
expected[i]= i + 1; }
Integer[] actual= to
(Ignore any warnings in the vertical ruler for now.)
to
, type 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]);
}
In this section you will use organize the import declarations in your source code. Open junit.samples.VectorTest.java file in the Java editor if you do not already have it open.
In this section, you will improve the code of the constructor of junit.framework.TestSuite. To make the intent of the code more clear, you will extract the code that collects test cases from base classes into a new method called collectTestMethods.
Class superClass= theClass;
Vector names= new Vector();
while
(Test.class.isAssignableFrom(superClass)) {
Method[] methods= superClass.getDeclaredMethods();
for (int i= 0; i < methods.length; i++) {
addTestMethod(methods[i],
names, constructor);
}
superClass= superClass.getSuperclass();
}
Java views
Java editor
Refactoring support
Templates
Using the Java editor
Showing and hiding elements
Showing single elements or whole Java files
Sorting elements in Java views
Using the local history
Using content assist
Using templates
Managing import statements
Refactoring
Refactoring with preview
Using the Hierarchy view
Opening a type hierarchy on a Java element
Opening a type hierarchy on the current text selection
Opening an editor for a selected element
Java Outline View
Java Content Assist
Templates Preferences
Organize Imports Preferences
Java Editor Preferences
Extract Method Errors
Type Hierarchy View