@Test
public void testEncrypt() throws UnsupportedEncodingException {

	
	/**
	 * 测试异常情况。
	 */
	Assert.assertEquals(0, encryCredentialManager.encrypt(null).length());
	
	
	/**
	 * 测试传入的参数不合法的情况。
	 */
	EncryCredentialInfo encryCredentialInfo = new EncryCredentialInfo();
	KeyService keyService = Mockito.mock(KeyService.class);
	encryCredentialManager.setKeyService(keyService);
	String result = encryCredentialManager.encrypt(encryCredentialInfo);
	checkData(result, encryCredentialInfo);
	
	
	/**
	 * 设置模拟服务，查询到的key为null.
	 */
	result = encryCredentialManager.encrypt(encryCredentialInfo);
	checkData(result, encryCredentialInfo);
	
	/**
	 * 设置模拟服务，查询到的key不是null.
	 */
	String keyId = "1001";
	Ki4soKey key = new Ki4soKey();
	key.setKeyId(keyId);
	key.setValue("dafdasfdasfds");
	encryCredentialInfo.setKeyId(keyId);
	Mockito.when(keyService.findKeyByKeyId(keyId)).thenReturn(key);
	result = encryCredentialManager.encrypt(encryCredentialInfo);
	checkData(result, encryCredentialInfo);

	/**
	 * 测试正常的情况。
	 */
	String appId = "1000";
	String userId = "test";
	encryCredentialInfo.setAppId(appId);
	Date now = new Date();
	encryCredentialInfo.setCreateTime(now);
	encryCredentialInfo.setExpiredTime(now);
	encryCredentialInfo.setKeyId(keyId);
	encryCredentialInfo.setUserId(userId);
	//加码。
	result = encryCredentialManager.encrypt(encryCredentialInfo);
	EncryCredential encryCredential = new EncryCredential(result);
	//解码。
	EncryCredentialInfo encryCredentialInfo2 = this.encryCredentialManager.decrypt(encryCredential);
	checkEncryCredentialInfo(encryCredentialInfo, encryCredentialInfo2);
}