Skip to content

Commit

Permalink
Issue #10548: Migrate to Inline Config Parser in MagicNumberCheckTest
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatj07 authored and romani committed Aug 19, 2021
1 parent 4757756 commit 514cc2e
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
1 change: 0 additions & 1 deletion pom.xml
Expand Up @@ -1662,7 +1662,6 @@

<exclude>**/NoCodeInFileCheckTest.class</exclude>

<exclude>**/MagicNumberCheckTest.class</exclude>

<exclude>**/HexFloatsTest.class</exclude>

Expand Down
Expand Up @@ -86,7 +86,8 @@ public void testDefault()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"236:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_1.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_1.java"), expected);
}

@Test
Expand Down Expand Up @@ -136,7 +137,8 @@ public void testIgnoreSome()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_2.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_2.java"), expected);
}

@Test
Expand Down Expand Up @@ -214,7 +216,8 @@ public void testIgnoreNone()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"245:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_3.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_3.java"), expected);
}

@Test
Expand Down Expand Up @@ -263,7 +266,8 @@ public void testIntegersOnly()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_4.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_4.java"), expected);
}

@Test
Expand Down Expand Up @@ -308,7 +312,8 @@ public void testIgnoreNegativeOctalHex() throws Exception {
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_5.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_5.java"), expected);
}

@Test
Expand Down Expand Up @@ -359,7 +364,8 @@ public void testIgnoreHashCodeMethod() throws Exception {
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_6.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_6.java"), expected);
}

@Test
Expand Down Expand Up @@ -402,7 +408,8 @@ public void testIgnoreFieldDeclaration()
"211:48: " + getCheckMessage(MSG_KEY, "-45"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber_7.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber_7.java"), expected);
}

@Test
Expand Down Expand Up @@ -465,7 +472,8 @@ public void testWaiverParentToken()
"0b1010000101000101101000010100010110100001010001011010000101000101L"),
"239:21: " + getCheckMessage(MSG_KEY, "122"),
};
verify(checkConfig, getPath("InputMagicNumber.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumber.java"), expected);
}

@Test
Expand All @@ -480,7 +488,7 @@ public void testMagicNumberRecordsDefault()
"29:29: " + getCheckMessage(MSG_KEY, "8"),
"33:20: " + getCheckMessage(MSG_KEY, "10"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputMagicNumberRecordsDefault.java"), expected);
}

Expand All @@ -496,7 +504,7 @@ public void testMagicNumberIgnoreFieldDeclarationRecords()
"29:29: " + getCheckMessage(MSG_KEY, "8"),
"33:20: " + getCheckMessage(MSG_KEY, "10"),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputMagicNumberIgnoreFieldDeclarationRecords.java"),
expected);
}
Expand All @@ -510,6 +518,7 @@ public void testIgnoreInAnnotationElementDefault() throws Exception {
"18:29: " + getCheckMessage(MSG_KEY, "10"),
"19:33: " + getCheckMessage(MSG_KEY, "11"),
};
verify(checkConfig, getPath("InputMagicNumberAnnotationElement.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMagicNumberAnnotationElement.java"), expected);
}
}
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down Expand Up @@ -154,7 +154,7 @@ class InputComplexButNotFlagged
public final Integer DefaultInit = new Integer(27); // violation
public final int SpecsPerDay = 24 * 60 * 60, SpecialRatio = 4 / 3;
public final javax.swing.border.Border StdBorder =
javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3); // violation
javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3); // 4 violations
}

enum MyEnum2
Expand Down Expand Up @@ -189,7 +189,7 @@ public int hashcode() {
}

{
int y=37;
int y=37; // violation
}

public TestHashCodeMethod() {
Expand Down
Expand Up @@ -53,14 +53,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
@@ -1,6 +1,6 @@
/*
MagicNumber
ignoreNumbers = 0,1,3.0,8,16,3000
ignoreNumbers = 0, 1, 3.0, 8, 16, 3000
ignoreHashCodeMethod = (default)false
ignoreAnnotation = true
ignoreFieldDeclaration = (default)false
Expand Down
Expand Up @@ -42,32 +42,32 @@ public void magicMethod() {
int int_var2 = (2); // violation
long long_var1 = 0L; // violation
long long_var2 = 0l; // violation
double double_var1 = 0D; // ok
double double_var2 = 0d; // ok
double double_var1 = 0D; // ok // violation
double double_var2 = 0d; // ok // violation

int[] int_array = new int[2]; // violation

int_var1 = 1 + 2; // violation
int_var1 = 1 + 2; // 2 violations
int_var1 += 1; // violation
double_var1 = 1.0 + 2.0; // violation
double_var1 = 1.0 + 2.0; // 2 violations

for (int i = 0; i < 2; i++); // violation
for (int i = 0; i < 2; i++); // 2 violations

if (1 < 2); // violation
if (1 < 2); // 2 violations

if (1.0 < 2.0); // violation
if (1.0 < 2.0); // 2 violations


int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0;
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5;

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0;
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5;

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ class Signed_5
public static final int CONST_PLUS_THREE = +3;
public static final int CONST_MINUS_TWO = -2;
private int mPlusThree = +3; // violation
private int mMinusTwo = -2; // violation
private int mMinusTwo = -2;
private double mPlusDecimal = +3.5;
private double mMinusDecimal = -2.5;
}
Expand Down
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down
Expand Up @@ -54,14 +54,14 @@ public void magicMethod() {

int int_magic1 = 3_000; // violation
double double_magic1 = 1.5_0; // violation
int int_magic2 = (3 + 4); // violation
int int_magic2 = (3 + 4); // 2 violations

int_array = new int[3]; // violation

int_magic1 += 3; // violation
double_magic1 *= 1.5; // violation

for (int j = 3; j < 5; j += 3) { // violation
for (int j = 3; j < 5; j += 3) { // 3 violations
int_magic1++;
}

Expand Down

0 comments on commit 514cc2e

Please sign in to comment.