Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some sonar fixes #1141

Merged
merged 1 commit into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions src/main/java/org/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected Assert() {
* okay)
* @param condition condition to be checked
*/
static public void assertTrue(String message, boolean condition) {
public static void assertTrue(String message, boolean condition) {
if (!condition) {
fail(message);
}
Expand All @@ -48,7 +48,7 @@ static public void assertTrue(String message, boolean condition) {
*
* @param condition condition to be checked
*/
static public void assertTrue(boolean condition) {
public static void assertTrue(boolean condition) {
assertTrue(null, condition);
}

Expand All @@ -60,7 +60,7 @@ static public void assertTrue(boolean condition) {
* okay)
* @param condition condition to be checked
*/
static public void assertFalse(String message, boolean condition) {
public static void assertFalse(String message, boolean condition) {
assertTrue(message, !condition);
}

Expand All @@ -70,7 +70,7 @@ static public void assertFalse(String message, boolean condition) {
*
* @param condition condition to be checked
*/
static public void assertFalse(boolean condition) {
public static void assertFalse(boolean condition) {
assertFalse(null, condition);
}

Expand All @@ -81,7 +81,7 @@ static public void assertFalse(boolean condition) {
* okay)
* @see AssertionError
*/
static public void fail(String message) {
public static void fail(String message) {
if (message == null) {
throw new AssertionError();
}
Expand All @@ -91,7 +91,7 @@ static public void fail(String message) {
/**
* Fails a test with no message.
*/
static public void fail() {
public static void fail() {
fail(null);
}

Expand All @@ -106,11 +106,12 @@ static public void fail() {
* @param expected expected value
* @param actual actual value
*/
static public void assertEquals(String message, Object expected,
public static void assertEquals(String message, Object expected,
Object actual) {
if (equalsRegardingNull(expected, actual)) {
return;
} else if (expected instanceof String && actual instanceof String) {
}
if (expected instanceof String && actual instanceof String) {
String cleanMessage = message == null ? "" : message;
throw new ComparisonFailure(cleanMessage, (String) expected,
(String) actual);
Expand Down Expand Up @@ -140,7 +141,7 @@ private static boolean isEquals(Object expected, Object actual) {
* @param expected expected value
* @param actual the value to check against <code>expected</code>
*/
static public void assertEquals(Object expected, Object actual) {
public static void assertEquals(Object expected, Object actual) {
assertEquals(null, expected, actual);
}

Expand All @@ -155,7 +156,7 @@ static public void assertEquals(Object expected, Object actual) {
* @param unexpected unexpected value to check
* @param actual the value to check against <code>unexpected</code>
*/
static public void assertNotEquals(String message, Object unexpected,
public static void assertNotEquals(String message, Object unexpected,
Object actual) {
if (equalsRegardingNull(unexpected, actual)) {
failEquals(message, actual);
Expand All @@ -171,7 +172,7 @@ static public void assertNotEquals(String message, Object unexpected,
* @param unexpected unexpected value to check
* @param actual the value to check against <code>unexpected</code>
*/
static public void assertNotEquals(Object unexpected, Object actual) {
public static void assertNotEquals(Object unexpected, Object actual) {
assertNotEquals(null, unexpected, actual);
}

Expand All @@ -194,7 +195,7 @@ private static void failEquals(String message, Object actual) {
* @param unexpected unexpected value to check
* @param actual the value to check against <code>unexpected</code>
*/
static public void assertNotEquals(String message, long unexpected, long actual) {
public static void assertNotEquals(String message, long unexpected, long actual) {
if (unexpected == actual) {
failEquals(message, Long.valueOf(actual));
}
Expand All @@ -207,7 +208,7 @@ static public void assertNotEquals(String message, long unexpected, long actual)
* @param unexpected unexpected value to check
* @param actual the value to check against <code>unexpected</code>
*/
static public void assertNotEquals(long unexpected, long actual) {
public static void assertNotEquals(long unexpected, long actual) {
assertNotEquals(null, unexpected, actual);
}

Expand All @@ -226,7 +227,7 @@ static public void assertNotEquals(long unexpected, long actual) {
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertNotEquals(String message, double unexpected,
public static void assertNotEquals(String message, double unexpected,
double actual, double delta) {
if (!doubleIsDifferent(unexpected, actual, delta)) {
failEquals(message, Double.valueOf(actual));
Expand All @@ -245,7 +246,7 @@ static public void assertNotEquals(String message, double unexpected,
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertNotEquals(double unexpected, double actual, double delta) {
public static void assertNotEquals(double unexpected, double actual, double delta) {
assertNotEquals(null, unexpected, actual, delta);
}

Expand All @@ -261,7 +262,7 @@ static public void assertNotEquals(double unexpected, double actual, double delt
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertNotEquals(float unexpected, float actual, float delta) {
public static void assertNotEquals(float unexpected, float actual, float delta) {
assertNotEquals(null, unexpected, actual, delta);
}

Expand Down Expand Up @@ -547,7 +548,7 @@ private static void internalArrayEquals(String message, Object expecteds,
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertEquals(String message, double expected,
public static void assertEquals(String message, double expected,
double actual, double delta) {
if (doubleIsDifferent(expected, actual, delta)) {
failNotEquals(message, Double.valueOf(expected), Double.valueOf(actual));
Expand All @@ -569,7 +570,7 @@ static public void assertEquals(String message, double expected,
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertEquals(String message, float expected,
public static void assertEquals(String message, float expected,
float actual, float delta) {
if (floatIsDifferent(expected, actual, delta)) {
failNotEquals(message, Float.valueOf(expected), Float.valueOf(actual));
Expand All @@ -591,14 +592,14 @@ static public void assertEquals(String message, float expected,
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertNotEquals(String message, float unexpected,
public static void assertNotEquals(String message, float unexpected,
float actual, float delta) {
if (!floatIsDifferent(unexpected, actual, delta)) {
failEquals(message, Float.valueOf(actual));
failEquals(message, actual);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These implementations (floatIsDifferent, doubleIsDifferent) were deliberate stylistic choices for readability. I don't feel strongly about the style, but feel that muddying the git history for a different stylistic change doesn't seem worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

static private boolean doubleIsDifferent(double d1, double d2, double delta) {
private static boolean doubleIsDifferent(double d1, double d2, double delta) {
if (Double.compare(d1, d2) == 0) {
return false;
}
Expand All @@ -609,7 +610,7 @@ static private boolean doubleIsDifferent(double d1, double d2, double delta) {
return true;
}

static private boolean floatIsDifferent(float f1, float f2, float delta) {
private static boolean floatIsDifferent(float f1, float f2, float delta) {
if (Float.compare(f1, f2) == 0) {
return false;
}
Expand All @@ -627,7 +628,7 @@ static private boolean floatIsDifferent(float f1, float f2, float delta) {
* @param expected expected long value.
* @param actual actual long value
*/
static public void assertEquals(long expected, long actual) {
public static void assertEquals(long expected, long actual) {
assertEquals(null, expected, actual);
}

Expand All @@ -640,7 +641,7 @@ static public void assertEquals(long expected, long actual) {
* @param expected long expected value.
* @param actual long actual value
*/
static public void assertEquals(String message, long expected, long actual) {
public static void assertEquals(String message, long expected, long actual) {
if (expected != actual) {
failNotEquals(message, Long.valueOf(expected), Long.valueOf(actual));
}
Expand All @@ -652,7 +653,7 @@ static public void assertEquals(String message, long expected, long actual) {
* instead
*/
@Deprecated
static public void assertEquals(double expected, double actual) {
public static void assertEquals(double expected, double actual) {
assertEquals(null, expected, actual);
}

Expand All @@ -662,7 +663,7 @@ static public void assertEquals(double expected, double actual) {
* instead
*/
@Deprecated
static public void assertEquals(String message, double expected,
public static void assertEquals(String message, double expected,
double actual) {
fail("Use assertEquals(expected, actual, delta) to compare floating-point numbers");
}
Expand All @@ -679,7 +680,7 @@ static public void assertEquals(String message, double expected,
* <code>actual</code> for which both numbers are still
* considered equal.
*/
static public void assertEquals(double expected, double actual, double delta) {
public static void assertEquals(double expected, double actual, double delta) {
assertEquals(null, expected, actual, delta);
}

Expand All @@ -695,8 +696,7 @@ static public void assertEquals(double expected, double actual, double delta) {
* <code>actual</code> for which both numbers are still
* considered equal.
*/

static public void assertEquals(float expected, float actual, float delta) {
public static void assertEquals(float expected, float actual, float delta) {
assertEquals(null, expected, actual, delta);
}

Expand All @@ -708,7 +708,7 @@ static public void assertEquals(float expected, float actual, float delta) {
* okay)
* @param object Object to check or <code>null</code>
*/
static public void assertNotNull(String message, Object object) {
public static void assertNotNull(String message, Object object) {
assertTrue(message, object != null);
}

Expand All @@ -718,7 +718,7 @@ static public void assertNotNull(String message, Object object) {
*
* @param object Object to check or <code>null</code>
*/
static public void assertNotNull(Object object) {
public static void assertNotNull(Object object) {
assertNotNull(null, object);
}

Expand All @@ -730,7 +730,7 @@ static public void assertNotNull(Object object) {
* okay)
* @param object Object to check or <code>null</code>
*/
static public void assertNull(String message, Object object) {
public static void assertNull(String message, Object object) {
if (object == null) {
return;
}
Expand All @@ -743,11 +743,11 @@ static public void assertNull(String message, Object object) {
*
* @param object Object to check or <code>null</code>
*/
static public void assertNull(Object object) {
public static void assertNull(Object object) {
assertNull(null, object);
}

static private void failNotNull(String message, Object actual) {
private static void failNotNull(String message, Object actual) {
String formatted = "";
if (message != null) {
formatted = message + " ";
Expand All @@ -764,7 +764,7 @@ static private void failNotNull(String message, Object actual) {
* @param expected the expected object
* @param actual the object to compare to <code>expected</code>
*/
static public void assertSame(String message, Object expected, Object actual) {
public static void assertSame(String message, Object expected, Object actual) {
if (expected == actual) {
return;
}
Expand All @@ -778,7 +778,7 @@ static public void assertSame(String message, Object expected, Object actual) {
* @param expected the expected object
* @param actual the object to compare to <code>expected</code>
*/
static public void assertSame(Object expected, Object actual) {
public static void assertSame(Object expected, Object actual) {
assertSame(null, expected, actual);
}

Expand All @@ -792,7 +792,7 @@ static public void assertSame(Object expected, Object actual) {
* @param unexpected the object you don't expect
* @param actual the object to compare to <code>unexpected</code>
*/
static public void assertNotSame(String message, Object unexpected,
public static void assertNotSame(String message, Object unexpected,
Object actual) {
if (unexpected == actual) {
failSame(message);
Expand All @@ -807,19 +807,19 @@ static public void assertNotSame(String message, Object unexpected,
* @param unexpected the object you don't expect
* @param actual the object to compare to <code>unexpected</code>
*/
static public void assertNotSame(Object unexpected, Object actual) {
public static void assertNotSame(Object unexpected, Object actual) {
assertNotSame(null, unexpected, actual);
}

static private void failSame(String message) {
private static void failSame(String message) {
String formatted = "";
if (message != null) {
formatted = message + " ";
}
fail(formatted + "expected not same");
}

static private void failNotSame(String message, Object expected,
private static void failNotSame(String message, Object expected,
Object actual) {
String formatted = "";
if (message != null) {
Expand All @@ -829,14 +829,14 @@ static private void failNotSame(String message, Object expected,
+ ">");
}

static private void failNotEquals(String message, Object expected,
private static void failNotEquals(String message, Object expected,
Object actual) {
fail(format(message, expected, actual));
}

static String format(String message, Object expected, Object actual) {
String formatted = "";
if (message != null && !message.equals("")) {
if (message != null && !"".equals(message)) {
formatted = message + " ";
}
String expectedString = String.valueOf(expected);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/junit/Assume.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
* @since 4.4
*/
public class Assume {

/**
* Do not instantiate.
* @deprecated since 4.13.
*/
@Deprecated
public Assume() {
}

/**
* If called with an expression evaluating to {@code false}, the test will halt and be ignored.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
* </pre>
*/
public class ResultMatchers {

/**
* Do not instantiate.
* @deprecated will be private soon.
*/
@Deprecated
public ResultMatchers() {
}

/**
* Matches if the tests are all successful
*/
Expand Down
Loading