Using JMockIt 1.12 and Eclipse Luna and I get "The allocated object is never used" errors. I tried:
@Test
public void testNullCase() {
new NonStrictExpectations() {{
TestClass.getPlug();
result = null;
}
...
};
To use SuppressWarnings I had to use something ugly like this:
@Test
public void testNullCase() {
@SuppressWarnings("unused")
NonStrictExpectations dummy = new NonStrictExpectations() {{
TestClass.getPlug();
result = null;
}
...
};
How to do this in a nicer way or am I missing something using JMockIt?
This warning can be turned off via:
Window/Preferences
Java/Compiler/Errors&Warnings/Potential Programming problems
Unused object allocation
.If you want to make that change persistent outside a particular Eclipse workspace, you can use the workspace mechanic. Or you could move the @SuppressWarnings("unused")
to the test class to disable it for all tests in the class.