0

In the code below, I'm supressing the warnings because I will be using the assertEquals method which is deprecated. The problem I'm having is that when I run the code below, I get the error:

MyTests.java:3: error: class, interface, or enum expected import org.junit.*;

@SuppressWarnings("deprecation")

import org.junit.*;
import static org.junit.Assert.*;


public class MyTests {


}
icymist
  • 11
  • 2
  • 2
    Place the annotation on the class, it's currently in an invalid location (you can't annotate import statements). – Slaw Aug 30 '19 at 20:03
  • `import org.junit.*; import static org.junit.Assert.*; @SuppressWarnings("deprecation") public class MyTests {` – Youcef LAIDANI Aug 30 '19 at 20:03
  • If you're actually _trying_ to suppress a warning originating from the import statements you should see [Suppress deprecated import warning in Java](https://stackoverflow.com/questions/1858021/suppress-deprecated-import-warning-in-java). Short answer is you can't due to a bug in the _Java Language Specification (JLS)_ and consequently javac; the bug was fixed in Java 9: [JDK-8032211](https://bugs.openjdk.java.net/browse/JDK-8032211). – Slaw Aug 30 '19 at 20:18

2 Answers2

1

The annotation must be on the class

import org.junit.*;
import static org.junit.Assert.*;

@SuppressWarnings("deprecation")
public class MyTests {


}

but you should avoid to use deprecated methods...

A method with the same name but with a different signature exists: assertEquals(double expected, double actual, double delta)

source: https://stackoverflow.com/a/33274105/5950567

DavidPi
  • 415
  • 3
  • 18
1

That annotation can't be in the beginning of the file, above the import statements. You could move it directly in front of the class declaration, but I guess that isn't what you want to do.

So even better: remove it completely!

Simply do not import/use deprecated classes or static methods. That is bad practice, and typically there are alternatives that should/can be used.

And please note: you really don't need any depracted imports for the packages you are using there. It is good practice to do avoid wild card imports anyway. Only import the things you need, and then only use the stuff that isn't deprecated. And that isn't something you do manually anyway. Any idea fixes that with one keystroke!

GhostCat
  • 137,827
  • 25
  • 176
  • 248