Sounds reasonable.

On 10/31/12 12:05 PM, "Meghna Kale" <meghna.k...@sungard.com> wrote:

>Chiradeep,
>
>Thanks for the response.
>I tried making the ProjectService a Mockito object, and it worked.
>The only problem that I faced was to pass the "id"   in the call
>(referring to ActivateProjectCmd.java).  I was not able to assign a value
>to" id " parameter as it is a private member.
>
>               Project project= _projectService.getProject(id);
>
>Can we make use of the public getId() method rather than using "id"
>directly in the code.
>
>So I had to set the id value in the setup() method or else it throws
>nullPointerException for not finding the id.
>
>public class ActivateProjectCmdTest extends TestCase {
>       
>       private ActivateProjectCmd activateProjectCmd;
>       private Parameter parameter;
>       
>
>       @Before
>       public void setUp() {
>               activateProjectCmd = new ActivateProjectCmd(){
>                       
>                       @Override
>                       public Long getId() {
>                               return 2L;
>                       }
>               };
>       }
>
>       @Test
>       public void testGetEntityOwnerIdForProject() {
>               Project project = Mockito.mock(Project.class);
>               Mockito.when(project.getId()).thenReturn(2L);
>               ProjectService projectService =
>Mockito.mock(ProjectService.class);
>               Account account = Mockito.mock(Account.class);
>               Mockito.when(account.getId()).thenReturn(2L);
>       
>Mockito.when(projectService.getProject(Mockito.anyLong())).thenReturn(proj
>ect);
>               
>       
>Mockito.when(projectService.getProjectOwner(Mockito.anyLong())).thenReturn
>(account);
>               activateProjectCmd._projectService = projectService;
>               
>               Assert.assertEquals(2L,
>activateProjectCmd.getEntityOwnerId());
>               
>       }
>}
>
>- Meghna.
>
>
>
>-----Original Message-----
>From: Chiradeep Vittal [mailto:chiradeep.vit...@citrix.com]
>Sent: Wednesday, October 31, 2012 12:50 AM
>To: Meghna Kale; Alex Huang
>Cc: CloudStack DeveloperList
>Subject: Re: need help for test cases of api/commands
>
>
>
>On 10/30/12 12:12 PM, "Meghna Kale" <meghna.k...@sungard.com> wrote:
>
>>_projectService =
>>ComponentLocator.inject(MockProjectServiceImpl.class);
>
>When you do this,  the _projectService is no longer a Mockito object.

Reply via email to