Skip to content

Commit

Permalink
Return Count Extended Check #195 Compilable UT inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkravin committed Sep 1, 2014
1 parent 6ef9456 commit 92c9970
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,28 @@ public void testMethodsMaxReturnLiteralsIsOne() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"25:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "twoReturnsInMethod", 2, 1),
"37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1)
"26:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "twoReturnsInMethod", 2, 1),
"38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
"92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1)
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
}

@Test
public void testMethodsMaxReturnLiteralsIsTwo() throws Exception
{

checkConfig.addAttribute("maxReturnCount", "2");
checkConfig.addAttribute("ignoreMethodLinesCount", "0"); // swithed off
checkConfig.addAttribute("minIgnoreReturnDepth", "5");
checkConfig.addAttribute("ignoreEmptyReturns", "false");
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 2),
"58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 2),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
Expand All @@ -60,9 +79,9 @@ public void testConstructorsMaxReturnLiteralsIsOne() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"28:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1),
"41:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1),
"63:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1),
"29:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1),
"42:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1),
"64:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckCtors.java"), expected);
Expand All @@ -79,8 +98,8 @@ public void testignoreMethodLinesCount() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
"38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
Expand All @@ -96,7 +115,7 @@ public void testignoreMethodLinesCount2() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
"58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
Expand All @@ -112,26 +131,27 @@ public void testminIgnoreReturnDepth() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"6:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod", 1, 0),
"10:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod2", 1, 0),
"7:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod", 1, 0),
"11:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod2", 1, 0),
"92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 1, 0)
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
}

@Test
public void testIgnoreEmptyReturns() throws Exception
public void testIgnoreNonEmptyReturns() throws Exception
{
checkConfig.addAttribute("maxReturnCount", "1");
checkConfig.addAttribute("ignoreMethodLinesCount", "0");
checkConfig.addAttribute("minIgnoreReturnDepth", "5");
checkConfig.addAttribute("ignoreEmptyReturns", "true");
checkConfig.addAttribute("ignoreEmptyReturns", "false");
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"28:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1),
"41:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1),
"63:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1),
"29:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1),
"42:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1),
"64:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckCtors.java"), expected);
Expand All @@ -147,7 +167,7 @@ public void testMethodsInMethods() throws Exception
checkConfig.addAttribute("topLinesToIgnoreCount", "0");

String[] expected = {
"100:24: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "handleEvent", 3, 1),
"104:24: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "handleEvent", 3, 1),
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethodsInMethods.java"),
Expand All @@ -165,7 +185,8 @@ public void testIgnoreMethodsNamesProperty() throws Exception
checkConfig.addAttribute("ignoreMethodsNames", "threeReturnsInMethod, twoReturnsInMethod");

String[] expected = {
"57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
"58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1),
"92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1)
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
Expand All @@ -182,7 +203,8 @@ public void testRegexIgnoreMethodsNamesProperty() throws Exception
checkConfig.addAttribute("ignoreMethodsNames", "(?iu)(?:TwO|Four)(?-iu)ReturnsInMethod");

String[] expected = {
"37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1),
"92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1)
};

verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.github.sevntu.checkstyle.checks.coding;
public class InputReturnCountExtendedCheckCtors
{

public int a = 0;

// one "return"
public InputReturnCountExtendedCheckCtors() {
return a;
return;
}

// one "return"
Expand All @@ -21,40 +22,40 @@ public InputReturnCountExtendedCheckCtors(int x) {
}
}
}
return a + a * a;
return;
}

// two "returns"
public InputReturnCountExtendedCheckCtors(int x, String s) {
System.out.println();
int a = x + s.length();
if (a != 4) {
return 1;
return;
}
else {
System.out.println(a);
return 2;
return;
}
}

// three "returns"
public InputReturnCountExtendedCheckCtors(String z, double y) {
System.out.println();
int a = z;
int a = Integer.parseInt(z);
y+=0.6;
if (a != 4)
{
return 1;
return;
}
else
{
if (a - 1 != 2) {
this.a = 0;
return 6;
return;
}
else {
System.out.println();
return 2;
return;
}
}
}
Expand All @@ -65,7 +66,7 @@ public InputReturnCountExtendedCheckCtors(String z, int x, double y) {
int a = x;
if (a != 4) {
if (a != 6) {
return 1;
return;
}
else {
a++;
Expand All @@ -75,11 +76,11 @@ public InputReturnCountExtendedCheckCtors(String z, int x, double y) {
else {
if (a - 1 != 2) {
this.a = 0;
return 6;
return;
}
else {
System.out.println();
return 2;
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package com.github.sevntu.checkstyle.checks.coding;
public class InputReturnCountExtendedCheckMethods
{

Expand Down Expand Up @@ -98,6 +99,7 @@ public int nm()
return 5;
}
}
return a;
}

}
Loading

0 comments on commit 92c9970

Please sign in to comment.