|
Cobertura example source code file (ConditionCalls.java)
The Cobertura ConditionCalls.java source codepackage test.condition; import org.apache.log4j.Logger; public class ConditionCalls { /* * See the note at FirstPassMethodInstrumenter.visitJumpInsn() * regarding initialization of static variables. This next static * is intended to cover that condition. */ public static String whatEver = null; private static final Logger logger = Logger.getLogger(ConditionCalls.class); public void call(int i) { if (i>=5) //set CALL_CONDITION_LINE_NUMBER to this line number { try { logger.error("whatEver"); //set CALL_IGNORE_LINE_NUMBER to this line number throw new RuntimeException(); } catch (Throwable t) { //eat it } finally { System.out.println("true"); } } else { System.out.println("false"); } } public void callLookupSwitch(int branch) { switch (branch) //set LOOKUP_SWITCH_LINE_NUMBER to this line number { case 1: System.out.println("1"); break; case 5: System.out.println("5"); break; default: System.out.println("default"); break; } } public String callTableSwitch(int branch) { int[][] multiArray; switch (branch) //set TABLE_SWITCH_LINE_NUMBER to this line number { case 0: return("0"); case 1: return("1"); case 2: return("2"); case 3: return("3"); case 4: return("4"); case 5: return("5"); case 6: return("6"); case 7: return("7"); case 8: return("8"); default: multiArray = new int[3][3]; return("" + multiArray[1][1]); } } public void callMultiCondition(int a, int b, int c) { //The c++ is to get SecondPassMethodInstrumenter.visitIincInsn called. if ((a == b) && (b >= 3) || (c++ < a)) //set MULTI_CONDITION_LINE_NUMBER to this line number { System.out.println("true"); } } public void callMultiCondition2(int a, int b, int c) { if ((a == b) && (b >= utilEcho(3)) || (c < a)) //set MULTI_CONDITION2_LINE_NUMBER to this line number { System.out.println("true"); } } int utilEcho(int number) { return number; } static { whatEver = "whatEver"; }; public static final int CALL_CONDITION_LINE_NUMBER = 17; public static final int CALL_IGNORE_LINE_NUMBER = 21; public static final int LOOKUP_SWITCH_LINE_NUMBER = 39; public static final int TABLE_SWITCH_LINE_NUMBER = 56; public static final int MULTI_CONDITION_LINE_NUMBER = 74; public static final int MULTI_CONDITION2_LINE_NUMBER = 82; } Other Cobertura examples (source code examples)Here is a short list of links related to this Cobertura ConditionCalls.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.