Package com.suarte.core.service

Source Code of com.suarte.core.service.ContactManagerImplTest

package com.suarte.core.service;

import com.suarte.core.service.impl.ContactManagerImpl;
import com.suarte.core.Contact;
import com.suarte.core.dao.ContactDao;
import java.util.ArrayList;
import java.util.List;

import org.appfuse.service.impl.BaseManagerMockTestCase;

import org.jmock.Expectations;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;

/**
* @date   Dec 20, 2010
* @author Ggutierrez
*/
public class ContactManagerImplTest extends BaseManagerMockTestCase {
    private ContactManagerImpl manager = null;
    private ContactDao dao = null;


    @Before
    public void setUp() {
        dao = context.mock(ContactDao.class);
        manager = new ContactManagerImpl(dao);
    }

    @After
    public void tearDown() {
        manager = null;
    }

    @Test
    public void testGetPerson() {
        log.debug("testing get...");

        final Long id = 7L;
        final Contact contact = new Contact();

        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).get(with(equal(id)));
            will(returnValue(contact));
        }});

        Contact result = manager.get(id);
        assertSame(contact, result);
    }

    @Test
    public void testGetPersons() {
        log.debug("testing getAll...");

        final List persons = new ArrayList();

        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).getAll();
            will(returnValue(persons));
        }});

        List result = manager.getAll();

        assertSame(persons, result);
    }

    @Test
    public void testSavePerson() {
        log.debug("testing save...");

        final Contact person = new Contact();
        // enter all required fields

        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).save(with(same(person)));
        }});

        manager.save(person);
    }

    @Test
    public void testRemovePerson() {
        log.debug("testing remove...");

        final Long id = -11L;

        // set expected behavior on dao
        context.checking(new Expectations() {{
            one(dao).remove(with(equal(id)));
        }});

        manager.remove(id);
    }
}
TOP

Related Classes of com.suarte.core.service.ContactManagerImplTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.