View Javadoc

1   package org.cateproject.controller.user;
2   
3   import java.util.Locale;
4   
5   import org.cateproject.controller.captcha.CaptchaChallenge;
6   import org.easymock.EasyMock;
7   import org.junit.Assert;
8   import org.junit.Before;
9   import org.junit.Test;
10  import org.unitils.UnitilsJUnit4;
11  import org.unitils.easymock.annotation.Mock;
12  import org.unitils.inject.annotation.InjectInto;
13  import org.unitils.inject.annotation.TestedObject;
14  
15  import com.octo.captcha.service.image.ImageCaptchaService;
16  
17  import eu.etaxonomy.cdm.api.service.IUserService;
18  
19  public class UserListControllerTest extends UnitilsJUnit4 {
20  	
21  	@Mock
22  	@InjectInto(property = "imageCaptchaService")
23  	ImageCaptchaService imageCaptchaService;
24  	
25  	@TestedObject
26  	private UserListController userController;
27  	
28  	private String captchaQuestion;
29  	
30  	@Before
31  	public void setUp() {		
32  		userController = new UserListController();
33  	   
34  	    imageCaptchaService = EasyMock.createMock(ImageCaptchaService.class);
35  	    
36  		captchaQuestion = "captchaQuestion";
37  	}
38  	
39  	@Test
40  	public void testShowCaptcha() throws Exception {	
41      	EasyMock.expect(imageCaptchaService.getQuestionForID(EasyMock.isA(String.class), EasyMock.isA(Locale.class))).andReturn(captchaQuestion);;
42      	EasyMock.replay(imageCaptchaService);
43      	
44  		CaptchaChallenge captchaChallenge = userController.referenceData(Locale.getDefault());
45  		EasyMock.verify(imageCaptchaService);
46  		
47  		Assert.assertNotNull(captchaChallenge.getId());
48  		Assert.assertNotNull(captchaChallenge.getQuestion());
49  		Assert.assertEquals(captchaQuestion, captchaChallenge.getQuestion());
50  	}
51  }