I have the following basic code in Eclipse:
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class GreeterTest {
private Greeter greeter = new Greeter();
@Test
public void greeterSaysHello() {
assertThat(greeter.sayHello(), containsString("Hello"));
}
}
Eclipse correctly recognizes that The method containsString(String) is undefined for the type GreeterTest . To resolve this, I want to import the following:
import static org.hamcrest.CoreMatchers.containsString;
However, the only Quick Fix ( Ctrl + 1 ) Eclipse suggests is Create method containsString(String) , rather than the above import. And Organize imports ( Ctl + Shift + O ) also doesn't do the trick.
Is there a different keyboard shortcut in Eclipse that can predict, based on my dependencies, that I may want to add the above import? For comparison, I believe in IntelliJ, this is done via Intention Actions ( Alt + Enter ).
This can be done by adding org.hamcrest.CoreMatchers
to Java Editor Favorites
Action Plan
CoreMatchers
Now go back to the error in your editor and use Ctrl + 1 This should show the wished match!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.