Hello Everyone,
I am trying to run the following program in coverage mode , directly using the 
EclEmma eclipse plugin as well as using the -javaagent option to collect 
coverage and take the dump and then create the analysis report. 

via eclipse plugin the live coverage gives me 100% coverage , but via the dump 
.exec file (even if I take the session dump from eclipse plugin) , the coverage 
is missing few part of the actionPerformed(ActionEvent)  method and gives only 
83% coveage . withing eclipse I can see this is getting covered 100% .  Any 
idea what is happening in the off-line coverage mode  ??

Thanks in Advance. 


Sample Program :

package simple.coverage.demo;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;

public class JavaCalculator implements ActionListener{

JFrame guiFrame;
JPanel buttonPanel;
JTextField numberCalc;
int calcOperation = 0;
int currentCalc;

public static void main(String[] args) {

     EventQueue.invokeLater(new Runnable()
     {

         public void run()
         {

             new JavaCalculator();         
         }
     });

}

public JavaCalculator()
{
    guiFrame = new JFrame();
    guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    guiFrame.setTitle("Simple Calculator");
    guiFrame.setSize(300,300);
    guiFrame.setLocationRelativeTo(null);
    numberCalc = new JTextField();
    numberCalc.setHorizontalAlignment(JTextField.RIGHT);
    numberCalc.setEditable(false);
    guiFrame.add(numberCalc, BorderLayout.NORTH);
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(4,4));   
    guiFrame.add(buttonPanel, BorderLayout.CENTER);

    for (int i=0;i<10;i++)
    {
        addNumberButton(buttonPanel, String.valueOf(i));
    }

    addActionButton(buttonPanel, 1, "+");
    addActionButton(buttonPanel, 2, "-");
    addActionButton(buttonPanel, 3, "*");
    addActionButton(buttonPanel, 4, "/");
    addActionButton(buttonPanel, 5, "^2");

    JButton equalsButton = new JButton("=");
    equalsButton.setActionCommand("=");
    equalsButton.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent event)
        {
            if (!numberCalc.getText().isEmpty())
            {
                int number = Integer.parseInt(numberCalc.getText()); 
                if (calcOperation == 1)
                {
                    int calculate = currentCalc  + number;
                    numberCalc.setText(Integer.toString(calculate));
                }
                else if (calcOperation == 2)
                {
                    int calculate = currentCalc  - number;
                    numberCalc.setText(Integer.toString(calculate));
                }
                else if (calcOperation == 3)
                {
                    int calculate = currentCalc  * number;
                    numberCalc.setText(Integer.toString(calculate));
                }
                else if (calcOperation == 4)
                {
                    int calculate = currentCalc  / number;
                    numberCalc.setText(Integer.toString(calculate));
                }
                else if (calcOperation == 5)
                {
                    int calculate = currentCalc  * currentCalc;
                    numberCalc.setText(Integer.toString(calculate));
                }
            }
        }
    });

    buttonPanel.add(equalsButton);
    guiFrame.setVisible(true);  
}

private void addNumberButton(Container parent, String name)
{
    JButton but = new JButton(name);
    but.setActionCommand(name);
    but.addActionListener(this);
    parent.add(but);
}

private void addActionButton(Container parent, int action, String text)
{
    JButton but = new JButton(text);
    but.setActionCommand(text);
    OperatorAction addAction = new OperatorAction(action);
    but.addActionListener(addAction);
    parent.add(but);
}

public void actionPerformed(ActionEvent event)
{
    String action = event.getActionCommand();

    numberCalc.setText(action);       
}

private class OperatorAction implements ActionListener
{
    private int operator;

    public OperatorAction(int operation)
    {
        operator = operation;
    }

    public void actionPerformed(ActionEvent event)
    {
        currentCalc = Integer.parseInt(numberCalc.getText()); 
        calcOperation = operator;
    }
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to