PageRenderTime 500ms CodeModel.GetById 243ms app.highlight 128ms RepoModel.GetById 123ms app.codeStats 0ms

/src/test/java/com/google/ie/business/service/impl/DeveloperServiceImplTest.java

http://thoughtsite.googlecode.com/
Java | 77 lines | 52 code | 18 blank | 7 comment | 0 complexity | d7f6c566a7088d40434ab0ba3fa2c158 MD5 | raw file
 1// Copyright 2009 Google Inc. All Rights Reserved.
 2
 3package com.google.ie.business.service.impl;
 4
 5import static org.junit.Assert.assertEquals;
 6import static org.mockito.Mockito.mock;
 7import static org.mockito.Mockito.when;
 8
 9import com.google.ie.business.dao.DeveloperDao;
10import com.google.ie.business.dao.impl.DeveloperDaoImpl;
11import com.google.ie.business.domain.Developer;
12import com.google.ie.business.domain.User;
13import com.google.ie.dto.RetrievalInfo;
14import com.google.ie.test.ServiceTest;
15
16import org.junit.Before;
17import org.junit.Test;
18
19import java.util.ArrayList;
20import java.util.List;
21
22/**
23 * Test case for DeveloperServiceImpl class
24 * 
25 * @author Surabhi Bhatnagar
26 * 
27 */
28public class DeveloperServiceImplTest extends ServiceTest {
29    private DeveloperServiceImpl developerService;
30    private DeveloperDao mockDeveloperDao = mock(DeveloperDaoImpl.class);
31
32    @Before
33    public void setUp() {
34        super.setUp();
35        developerService = new DeveloperServiceImpl();
36        developerService.setDeveloperDao(mockDeveloperDao);
37
38    }
39
40    @Test
41    public void updateStatus() {
42
43        Developer dev = new Developer();
44        dev.setKey("developerKey");
45
46        Developer newDev = new Developer();
47        newDev.setKey("developerKey");
48        newDev.setStatus("New_Request");
49
50        when(mockDeveloperDao.findEntityByPrimaryKey(Developer.class, dev.getKey()))
51                        .thenReturn(dev);
52        when(mockDeveloperDao.saveDeveloper(dev)).thenReturn(newDev);
53        assertEquals("New_Request", newDev.getStatus());
54    }
55
56    @Test
57    public void getDeveloperByUserKey() {
58        RetrievalInfo retrievalInfo = new RetrievalInfo();
59
60        Developer dev = new Developer();
61        dev.setKey("developerKey");
62
63        List<Developer> devList = new ArrayList<Developer>();
64        devList.add(dev);
65        Developer newDev = new Developer();
66        newDev.setKey("developerKey");
67        newDev.setStatus("New_Request");
68
69        User user = new User();
70        user.setUserKey("userKey");
71
72        when(mockDeveloperDao.getDevelopersByUserKey(user.getUserKey(), retrievalInfo))
73                        .thenReturn(devList);
74        assertEquals("developerKey", devList.get(0).getKey());
75    }
76
77}