> I'm unable to get DAOIMPL value and I'm always getting value from Dao
> -----------------------------------------------------------------------
>
> Key: JMOCK-209
> URL:
http://jira.codehaus.org/browse/JMOCK-209> Project: jMock
> Issue Type: Improvement
> Components: Documentation
> Environment: Jmock Unit test issue
> Reporter: ramareddy
> Assignee: Nat Pryce
> Attachments: conductor.rar
>
>
> I had write sample Jmock Unit tesing Code :
> Problem : In my code Always I got the true result only.In case if i change to "ramaw" instead of "rama " .
> Could u pls solve my prb.
> Thanks for advance :
> I placed my code over here :
> JmocktestBl.java (main Jmock test program)
> package conductor;
> import org.jmock.Mock;
> import org.jmock.MockObjectTestCase;
> public class JmocktestBl extends MockObjectTestCase {
> final String name = "ramaw";
> boolean validUser = true;
> Mock mockUsersDao;
> Bl bl = (Bl) BeanLoadClass.getBean("bl");
> // Bl bl = new Bl();
> protected void setUp() throws Exception {
> mockUsersDao = new Mock(UsersDao.class);
> bl.setUsersDao((UsersDao) mockUsersDao.proxy());
> }
> public void testController() throws Exception {
> mockUsersDao.expects(once()).method("login").with(eq(name))
> .will(returnValue(validUser));
>
> boolean check = bl.checkLogin(name);
> System.out.println("check :"+check);
> assertEquals(validUser,check);
> mockUsersDao.verify();
>
> }
> }
> BL.java program :
> package conductor;
> public class Bl {
> private UsersDao usersDao;
>
> public boolean checkLogin(String userName){
> //usersDao = new UsersDaoImpl();
> //usersDao = (UsersDao) BeanLoadClass.getBean("usersDao");
> boolean validUser = usersDao.login(userName);
> System.out.println("validUser :"+validUser);
> return validUser;
> }
> public void setUsersDao(UsersDao usersDao) {
> this.usersDao = usersDao;
> }
> }
> My dao :
> package conductor;
> public interface UsersDao {
> public boolean login(String name);
> }
> My dao Impl program :
> package conductor;
> public class UsersDaoImpl implements UsersDao {
> boolean valid = false;
> public boolean login(String name) {
> if (name.equalsIgnoreCase("rama")) {
> valid = true;
> }
> System.out.println("daoImpl :" + valid);
> return valid;
> }
> }
> Loading Spring Xml file using below program :
> package conductor;
> import org.springframework.context.ApplicationContext;
> import org.springframework.context.support.ClassPathXmlApplicationContext;
> public class BeanLoadClass {
> private static ApplicationContext ctx = null;
> static {
> String[] paths = {"conductor/spring-servlet.xml"};
> ctx = new ClassPathXmlApplicationContext(paths);
> }
>
> public static Object getBean(String beanName) {
> Object objDAO = null;
> try {
> objDAO = ctx.getBean(beanName);
>
> } catch (Exception e) {
>
> e.printStackTrace();
> }
> return objDAO;
> }
> }
> this is my spring XML file :
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="
http://www.springframework.org/schema/beans"
> xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
>
> <bean id="usersDao" class="conductor.UsersDaoImpl"></bean>
> <bean id="bl" class="conductor.Bl">
> <property name="usersDao"><ref bean="usersDao"/></property>
> </bean>
> </beans>