TestMIDLet Coverage Report

Metrics: CCN: 1,364 Methods: 11
NCSS: 4,455 Classes: -
JVDC: 0% Packages: -
Need help?
Package # Classes Line Coverage Branch Coverage Method Coverage
KITExcellence 14
88.5% 
89.5% 
89.1% 

Class Line Coverage Branch Coverage Method Coverage
SpriteData.Action
95.2% 
100% 
100% 

 1  
 package KITExcellence;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.InputStream;
 5  
 import java.util.Hashtable;
 6  
 import java.util.Vector;
 7  
 
 8  
 import javax.microedition.lcdui.Graphics;
 9  
 import javax.microedition.lcdui.Image;
 10  
 
 11  
 public class SpriteData {
 12  
         private Hashtable actions = new Hashtable();
 13  
         
 14  
         private static class Frame {
 15  
                 public Image image;
 16  
                 /* TODO: other stuff */
 17  
         }
 18  
         
 19  
         public Action getDefaultAction() {
 20  
                 return (Action) actions.elements().nextElement();
 21  
         }
 22  
         
 23  
         public Action getAction(String name) {
 24  
                 Action action = (Action) actions.get(name);
 25  
                 if (action == null)
 26  
                         throw new RuntimeException("Action " + name + " not found");
 27  
                 return action;
 28  
         }
 29  
         
 30  
         protected static class Action {
 31  
                 
 32  2
                 public Action(String name) {
 33  2
                         this.name = name;
 34  2
                         this.fps  = 10;
 35  2
                 }
 36  
                 
 37  
                 public void addFrame(Image image) {
 38  12
                         Frame frame = new Frame();
 39  12
                         frame.image = image;
 40  12
                         frames.addElement(frame);
 41  12
                 }
 42  
                 
 43  
                 public void addFrame(String imageName) throws IOException {
 44  12
                         InputStream input = Action.class.getResourceAsStream(imageName);
 45  12
                         if (input == null) {
 46  0
                                 throw new IOException("File " + input + " not found");
 47  
                         }
 48  12
                         Image image = Image.createImage(input);
 49  12
                         addFrame(image);
 50  12
                 }
 51  
                 
 52  
                 public String getName() {
 53  2
                         return name;
 54  
                 }
 55  
                 
 56  
                 public int getFrameCount() {
 57  228
                         return frames.size();
 58  
                 }
 59  
                 
 60  
                 public float getFps() {
 61  221
                         return fps;
 62  
                 }
 63  
                 
 64  
                 public void drawFrame(Graphics g, int x, int y, int num) {
 65  221
                         Frame frame = (Frame) frames.elementAt(num);
 66  221
                         g.drawImage(frame.image, x, y, Graphics.TOP | Graphics.LEFT);
 67  221
                 }
 68  
                 
 69  
                 private String name;
 70  2
                 private Vector frames = new Vector();
 71  
                 private float fps;
 72  
         }
 73  
 
 74  
         public void testCreateTux() throws IOException {
 75  
                 /* testdata */
 76  
                 Action walkright = new Action("walk-right");
 77  
                 String base = "/tux/";
 78  
                 walkright.addFrame(base + "largetux-walk-right-0.png");
 79  
                 walkright.addFrame(base + "largetux-walk-right-1.png");
 80  
                 walkright.addFrame(base + "largetux-walk-right-2.png");
 81  
                 walkright.addFrame(base + "largetux-walk-right-3.png");
 82  
                 walkright.addFrame(base + "largetux-walk-right-4.png");
 83  
                 walkright.addFrame(base + "largetux-walk-right-5.png");
 84  
                 actions.put(walkright.getName(), walkright);                
 85  
         }
 86  
         
 87  
         public void testCreateSnowball() throws IOException {
 88  
                 Action roll = new Action("roll");
 89  
                 String base = "/snowball/";
 90  
                 roll.addFrame(base + "left-0.png");
 91  
                 roll.addFrame(base + "left-1.png");
 92  
                 roll.addFrame(base + "left-2.png");
 93  
                 roll.addFrame(base + "left-3.png");
 94  
                 roll.addFrame(base + "left-4.png");
 95  
                 roll.addFrame(base + "left-5.png");
 96  
                 actions.put(roll.getName(), roll);
 97  
         }
 98  
 }

Legend:
Instrumented line CCN: Cyclomatic Complexity
Covered line NCSS: Non-Commenting Source Statement
Uncovered line JVDC: JaVaDoc Comment