Why doesn't intellij suggest org.mockito.Mockito dependency when using verify()? - intellij-idea

When creating a new test, I have issues importing mockito methods into the class.
The class looks like
#ExtendWith(SpringExtension.class)
#SpringBootTest(classes = MainSpringBootApplication.class)
class CoolServiceTest {
#Autowired
SomeService someService;
#Test
void testGetInstitutionsCache_ShouldNotSecondTime() {
assertEquals(someService.getName(), "bob");
verify(idsClientMock, times(1));
}
}
In the import menu of intellij I don't see the option to import org.mockito.Mockito which I know where the package resides.
Instead I get the option to add;
import static org.testcontainers.shaded.com.google.common.base.Verify.verify;
(obviously not what I want)
I can get around it by typing the full Mockito.verify and then adding an on-demand static import to tidy the code.
The package is definitely installed and available to use, but intellij won't pick it up automatically.

Related

org.jetbrains.annotations.NotNull instead of javax.annotation.Nonnull when implement method in Intellij IDEA

After recent JetBrains Intellij IDEA updates I found out that when I'm trying to implement method annotated with javax.annotation.Nonnull - IDE implements it with org.jetbrains.annotations.NotNull instead.
Example:
If you have an interface:
import javax.annotation.Nonnull;
interface User {
#Nonnull
String getName();
}
it will be implemented as:
import org.jetbrains.annotations.NotNull;
class Customer implements User {
#NotNull
#Override
public String getName() {
return null;
}
}
The question is how to configure IDE to implement methods with strict validation annotation?
Looks like a defect (https://youtrack.jetbrains.com/issue/IDEA-253324) although there is a workaround exist:
Inspections > Java > Probable bugs > Nullability problems > #NotNull/#Nullable problems > Configure Annotations. Set javax.annotation.Nullable/javax.annotation.Nonnull as defaults and restart the IDE.
To add the library with annotations to a Gradle project, add the implementation org.jetbrains:annotations:23.0.0 dependency to the build.gradle file.

How can I add a new preference to my eclipse plugin?

I have an eclipse plugin. I want to add a new preference to this particular plugin. The type of preference is just a true/false kind of behavior which can be achieved with just a checkbox.
I have created this class
``
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import XXXXXXXXXX.MyPlugin;
/**
* Preference page
*/
public class MyPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public MyPreferencePage() {
super(GRID);
setPreferenceStore(MyPlugin.getDefault().getPreferenceStore());
setDescription(Messages.MyPreferencePage_PREFERENCES_DESCRIPTION);
}
/**
* Creates the field editors. Field editors are abstractions of the common GUI blocks needed to
* manipulate various types of preferences. Each field editor knows how to save and restore
* itself.
*/
#Override
public void createFieldEditors() {
addField(new BooleanFieldEditor(PreferenceConstants.SHOW_REPORT,
Messages.MyPreferencePage_SHOW_REPORT, getFieldEditorParent()));
}
#Override
public void init(IWorkbench workbench) {
}
}
``
I have updated the extensions tab of plugin.xml accordingly.
Build is successful and I can see my newly created preference under windows -> preference. But when I click it, I can only see the description of the plugin. The boolean field which I have added is missing on the preference page.
Please help me in understanding what went wrong.

initializationError when running Junit test in static

I have been on a search recently for an answer to my question and I cannot seem to find it. I am trying to execute a simple test to run a JUnit test in static. When I try to execute the test I receive the following Failure.
java.lang.Exception: Method SimpleINt()should not be static.
I have JUnit 4 and hamcrest installed and pathsbuilt.
(I am still new to Selenium/Java so I am sure there is an easy explanation for this.)
package iMAP;
import org.junit.Test;
public class Test1 {
#Test
public static void SimpleINt ()
{
int i = 34;
System.out.println(i);
}
}
The JUnit documentation for #Test states:
The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure.
So, what is implicitly said here: the expectation is that #Test is only used for non static methods.
Beyond that: don't use keywords because you can. Learn what they mean. And static is something that you rather avoid (instead of using it all over the place).
Junit Methods should not be static as much I read and study. Just delete Static and try this:
package iMAP;
import org.junit.Test;
public class Test1 {
#Test
public void SimpleINt ()
{
int i = 34;
System.out.println(i);
}
}

What is `static inject...`

I found this line of code in Aurelia Dialog
static inject = [DialogService];
This is the full class:
import {Prompt} from './prompt';
import {DialogService} from '../dialog-service';
export class CommonDialogs {
static inject = [DialogService];
constructor(dialogService){
this.dialogService = dialogService;
}
prompt(question){
return this.dialogService.open({viewModel:Prompt, model:question});
};
}
What is the static inject doing? I get that it is injecting the dialog service into the constructor. But why do it this way instead of the usual inject?
As the blog post you linked to mentions, static inject was the original way to do dependency injection. Once Babel started supporting decorators, we implemented the inject decorator to make Aurelia code look a little nicer. Under the covers, it simply adds the inject property to the class at runtime (https://github.com/aurelia/dependency-injection/blob/master/src/decorators.js#L13).

Can Jython-based Java classes from an Eclipse PyDev project code be referenced by an Eclipse plugin project?

The following explains my attempts at trying to make a hybrid PyDev/Eclipse plugin project. I have since discovered that even if I make a separate PyDev project, I cannot use my PyDev Jython-based Java classes by referencing the project in a plug-in project. On the other hand, I can use the PyDev Java classes in a separate project that is NOT a plugin project.
I've got an eclipse plugin that I've also set as a PyDev project. I built it based on Jython Book v1.0 documentation chapter 10 and chapter 11.
When I run Main as seen below, I see
1 BUIDING-A 100 MAIN ST
When I try to do the same thing within a plug-in project that is set as a PyDev project (right click on project->Pydev->Set as Pydev Project), I get an ImportError: no module named Building. It seems like the plugin nature of the project is trumping the PyDev nature of the project.
Any ideas?
I've put the Main function below followed by some support code.
package org.jython.book;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jython.book.interfaces.BuildingType;
import org.jython.book.util.JythonObjectFactory;
public class Main {
public static void main(String[] args) {
// Obtain an instance of the object factory
JythonObjectFactory factory = JythonObjectFactory.getInstance();
// Call the createObject() method on the object factory by
// passing the Java interface and the name of the Jython module
// in String format. The returning object is casted to the the same
// type as the Java interface and stored into a variable.
BuildingType building = (BuildingType) factory.createObject(
BuildingType.class, "Building");
// Populate the object with values using the setter methods
building.setBuildingName("BUIDING-A");
building.setBuildingAddress("100 MAIN ST.");
building.setBuildingId(1);
System.out.println(building.getBuildingId() + " " + building.getBuildingName() + " " +
building.getBuildingAddress());
}
}
Here is the JythonObjectFactory which should be exactly like what is in [Jython Book v1.0 documentation chapter 10][3], with typos corrected, of course :-)
package mypackage.files.util;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
/**
* Object factory implementation that is defined
* in a generic fashion.
*
*/
public class JythonObjectFactory {
private static JythonObjectFactory instance = null;
private static PyObject pyObject = null;
protected JythonObjectFactory() {
}
/**
* Create a singleton object. Only allow one instance to be created
*/
public static JythonObjectFactory getInstance(){
if(instance == null){
instance = new JythonObjectFactory();
}
return instance;
}
/**
* The createObject() method is responsible for the actual creation of the
* Jython object into Java bytecode.
*/
public static Object createObject(Object interfaceType, String moduleName){
Object javaInt = null;
// Create a PythonInterpreter object and import our Jython module
// to obtain a reference.
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from " + moduleName + " import " + moduleName);
pyObject = interpreter.get(moduleName);
try {
// Create a new object reference of the Jython module and
// store into PyObject.
PyObject newObj = pyObject.__call__();
// Call __tojava__ method on the new object along with the interface name
// to create the java bytecode
javaInt = newObj.__tojava__(Class.forName(interfaceType.toString().substring(
interfaceType.toString().indexOf(" ")+1,
interfaceType.toString().length())));
} catch (ClassNotFoundException ex) {
Logger.getLogger(JythonObjectFactory.class.getName()).log(Level.SEVERE, null, ex);
}
return javaInt;
}
}
If you have multiple natures added to the project, all builders related to those projects will be invoked by Eclipse. So if the build fails with some PyDev related error message, this really indicates a problem with the PyDev part, not with PDE. Maybe you are missing some additional files or project settings for that project?
Generally speaking, you should avoid mixing multiple natures in one project. This often leads to trouble, because most builders and other extensions expect that they are "the one and only" tinkering with a project. And almost all use cases involving multiple natures can more easily be solved by having two different projects, where one project references the other project (and can then access resources of that referenced project). See Project properties -> Referenced Projects for that.