incubator-cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chiradeep Vittal <Chiradeep.Vit...@citrix.com>
Subject Re: need help for test cases of api/commands
Date Wed, 31 Oct 2012 20:06:22 GMT
Sounds reasonable.

On 10/31/12 12:05 PM, "Meghna Kale" <meghna.kale@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.Vittal@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.kale@sungard.com> wrote:
>
>>_projectService =
>>ComponentLocator.inject(MockProjectServiceImpl.class);
>
>When you do this,  the _projectService is no longer a Mockito object.


Mime
View raw message