The assertTrue() method seems to be quite a normal static method like:
public static void assertTrue() {
...
}
but when it's called, it looks so strange:
Assert.assertTrue(condition); //Should look like this.
assertTrue(condition); //But in fact it looks like this.
Why? And if I want to do something the same, what should I do?
public static class Logger() {
public static void log() {
...
}
}
Logger.log(someMessage); //Not cool
log(someMessage); //cool!
Thanks a lot.
Go to the top of your source code file and look at the imports. You should see something like this:
import static some.packages.Assert.assertTrue;
// or
import static some.packages.Assert.*;
This is a static
import. Basically what it does is it makes your specified member(s) as if they are static members in your class, so you can call them without the class name!
This can be done with Logger
too!
import static whatever.packages.your.logger.is.in.Logger.log;