SampleMIDlet Coverage Report |
|
| Package | # Classes | Line Coverage | Branch Coverage | Method Coverage | ||||||||||||
| org.cobertura4j2me.sample | 4 |
|
|
|
| Class | Line Coverage | Branch Coverage | Method Coverage | ||||||||||||
| SampleMIDlet |
|
|
|
| 1 | /* |
|
| 2 | * Cobertura for J2ME - http://www.coberura4j2me.org |
|
| 3 | * |
|
| 4 | * Copyright (C) 2005, 2007 Ludovic Dewailly <ludovic.dewailly@cobertura4j2me.org> |
|
| 5 | * |
|
| 6 | * Cobertura for J2ME is free software; you can redistribute it and/or modify |
|
| 7 | * it under the terms of the GNU General Public License as published |
|
| 8 | * by the Free Software Foundation; either version 2 of the License, |
|
| 9 | * or (at your option) any later version. |
|
| 10 | * |
|
| 11 | * Cobertura for J2ME is distributed in the hope that it will be useful, but |
|
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 14 | * General Public License for more details. |
|
| 15 | * |
|
| 16 | * You should have received a copy of the GNU General Public License |
|
| 17 | * along with Cobertura; if not, write to the Free Software |
|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
| 19 | * USA |
|
| 20 | */ |
|
| 21 | package org.cobertura4j2me.sample; |
|
| 22 | ||
| 23 | import javax.microedition.lcdui.Command; |
|
| 24 | import javax.microedition.lcdui.CommandListener; |
|
| 25 | import javax.microedition.lcdui.Display; |
|
| 26 | import javax.microedition.lcdui.Displayable; |
|
| 27 | import javax.microedition.lcdui.Form; |
|
| 28 | import javax.microedition.midlet.MIDlet; |
|
| 29 | import javax.microedition.midlet.MIDletStateChangeException; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * This is a sample MIDlet illustrating the use of Cobertura for J2ME. |
|
| 33 | * |
|
| 34 | * @author Ludovic Dewailly |
|
| 35 | */ |
|
| 36 | 1 | public class SampleMIDlet extends MIDlet implements CommandListener, Runnable { |
| 37 | ||
| 38 | private Form form; |
|
| 39 | 1 | private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 1); |
| 40 | 1 | private static final Command CMD_GO = new Command("Go", Command.OK, 1); |
| 41 | ||
| 42 | ||
| 43 | /* (non-Javadoc) |
|
| 44 | * @see javax.microedition.midlet.MIDlet#destroyApp(boolean) |
|
| 45 | */ |
|
| 46 | protected void destroyApp(boolean arg0) throws MIDletStateChangeException { |
|
| 47 | // the intrumenter adds here a call to the persistance to save |
|
| 48 | // the coverage data prior to exiting the application. |
|
| 49 | 1 | sayGoodBye(); |
| 50 | 1 | } |
| 51 | ||
| 52 | /* (non-Javadoc) |
|
| 53 | * @see javax.microedition.midlet.MIDlet#pauseApp() |
|
| 54 | */ |
|
| 55 | protected void pauseApp() { |
|
| 56 | // nothing to do |
|
| 57 | 0 | } |
| 58 | ||
| 59 | /* (non-Javadoc) |
|
| 60 | * @see javax.microedition.midlet.MIDlet#startApp() |
|
| 61 | */ |
|
| 62 | protected void startApp() throws MIDletStateChangeException { |
|
| 63 | 1 | form = new Form("HelloWorld"); |
| 64 | 1 | form.append("This is a sample MIDlet demonstrating Cobertura 4 J2ME use."); |
| 65 | ||
| 66 | 1 | form.append("\nNote that it is important that the MIDlet exists \"gracefully\" to garanty that all the coverage data is saved!"); |
| 67 | ||
| 68 | 1 | form.append("\nPress Go when you're ready."); |
| 69 | ||
| 70 | 1 | form.addCommand(CMD_EXIT); |
| 71 | 1 | form.addCommand(CMD_GO); |
| 72 | 1 | form.setCommandListener(this); |
| 73 | ||
| 74 | 1 | Display.getDisplay(this).setCurrent(form); |
| 75 | 1 | } |
| 76 | ||
| 77 | /* (non-Javadoc) |
|
| 78 | * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Displayable) |
|
| 79 | */ |
|
| 80 | public void commandAction(Command cmd, Displayable displayable) { |
|
| 81 | 2 | if (cmd == CMD_GO) { |
| 82 | 1 | go(); |
| 83 | 1 | } |
| 84 | 1 | else if (cmd == CMD_EXIT) { |
| 85 | try { |
|
| 86 | // !!! ALWAYS INVOKE THIS METHOD UPON EXIT !!! |
|
| 87 | 1 | destroyApp(true); |
| 88 | } |
|
| 89 | 0 | catch (MIDletStateChangeException e) { |
| 90 | // TODO handle it properly |
|
| 91 | 1 | } |
| 92 | 1 | notifyDestroyed(); |
| 93 | } |
|
| 94 | 2 | } |
| 95 | ||
| 96 | /** |
|
| 97 | * The go method! |
|
| 98 | */ |
|
| 99 | private void go() { |
|
| 100 | 1 | new Thread(this).start(); |
| 101 | 1 | } |
| 102 | ||
| 103 | private void sayGoodBye() { |
|
| 104 | 1 | form.append("\nGood Bye"); |
| 105 | 1 | } |
| 106 | ||
| 107 | /* (non-Javadoc) |
|
| 108 | * @see java.lang.Runnable#run() |
|
| 109 | */ |
|
| 110 | public void run() { |
|
| 111 | 1 | SomeClass c = new SomeClass(form); |
| 112 | 1 | c.doSomething(); |
| 113 | 11 | while (!c.isItDone()) { |
| 114 | 10 | form.append("\nNot yet done"); |
| 115 | try { |
|
| 116 | 10 | Thread.sleep(500); |
| 117 | } |
|
| 118 | 0 | catch (InterruptedException e) { |
| 119 | // TODO Auto-generated catch block |
|
| 120 | 0 | e.printStackTrace(); |
| 121 | 10 | } |
| 122 | 0 | } |
| 123 | 1 | form.append("Done! You can now press Exit"); |
| 124 | 1 | } |
| 125 | } |
| Instrumented line | CCN: | Cyclomatic Complexity | |
| Covered line | NCSS: | Non-Commenting Source Statement | |
| Uncovered line | JVDC: | JaVaDoc Comment |