samedi 5 septembre 2015

properties are null even pass values from the test in java?

I have 2 class mentioned bellow . first one :EmployeeDetails

package com.pacakge.emp;

public class EmployeeDetails {

    private String name; 
    private double monthlySalary;
    private int  age;

    //return name 
    public String getName()

    {
        return name;
    }
    //set the name 
    public void setName(String name)
    {
        name= this.name;
    }
   //get month sal 
    public double getMonthSal()
    {
        return monthlySalary;
    }
    //set month salary 
    public void setMonthSalry(double monthlySalary)
    {
        monthlySalary =this.monthlySalary;  
    }
//:::::::::::::::::::::::::::::::::::::::;
//Second one :EmpBusinessLogic 
package com.pacakge.emp;

public class EmpBusinessLogic {

    //calculate yearly salary of the employee 
    public double calculateYearlySalary(EmployeeDetails empdetails)
    {
        double yearlySalary;
        yearlySalary =empdetails.getMonthSal()*12;

        return yearlySalary;

    }

//::::::::::::::::
//This is my test class
package com.pacakge.emp;


import org.testng.Assert;
import org.testng.annotations.Test;

public class TestEmployeeDetails {


    EmployeeDetails emp = new EmployeeDetails();

    EmpBusinessLogic EmpBusinessLogic = new EmpBusinessLogic();


       // Test to check yearly salary
       @Test
       public void testCalculateYearlySalary() {

          emp.setName("saman");
          emp.setAge(25);
          emp.setMonthSalry(8000.0);
          emp.getName();
          System.out.println(emp.getName());



          double salary = EmpBusinessLogic.calculateYearlySalary(emp);
          Assert.assertEquals(salary, "8000");
       }
}

Even if I have passed values from Test method values are not pass to the properties . " System.out.println(emp.getName());" print null without any value. any issue in the code ? couldn't find what is the issue ...

Aucun commentaire:

Enregistrer un commentaire