域对象被嘲笑?

时间:2017-12-22 11:38:48

标签: java mocking jmockit

这是我的EmployeeServiceTest.java

@RunWith(JMockit.class)
public class EmployeeServiceTest {

    @Tested
    private EmployeeServiceImpl employeeService;

    @Injectable
    private EmployeeDaoImpl employeeDao;

    @Test
    public void testGetEmployee() {

        Employee employee= new Employee();
        employee.setAddress("Test Address");

        new Expectations() {
            {
                employeeDao.get(Employee.class, 1L);result = employee;
            }
        };

        Employee employee1 = employeeService.getEmployee(1L);
        System.out.println(employee1.getAddress()); // Line 1   
    }
}

这是我的EmployeeServiceImpl。java

public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeDao employeeDao;

    public Employee getEmployee(Long id) {
        return employeeDao.get(Employee.class, id);
    }
}

问题是当我在System.out.println(employee.getAddress()) line no1时,我将地址设为空而不是Test Address。我不确定是什么 问题在这里?

0 个答案:

没有答案