Commit e54bd6fd authored by Liang Ding's avatar Liang Ding

🎨 Clean code

@nanolikeyou Thanks for your PR 👍
parent bbdded3a
...@@ -49,7 +49,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -49,7 +49,7 @@ import javax.servlet.http.HttpServletResponse;
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:385321165@qq.com">DASHU</a> * @author <a href="mailto:385321165@qq.com">DASHU</a>
* @author <a href="https://github.com/nanolikeyou">nanolikeyou</a> * @author <a href="https://github.com/nanolikeyou">nanolikeyou</a>
* @version 1.1.0.10, Aug 13, 2017 * @version 1.1.0.11, Aug 14, 2017
* @since 0.4.0 * @since 0.4.0
*/ */
@Service @Service
...@@ -278,6 +278,7 @@ public class UserMgmtService { ...@@ -278,6 +278,7 @@ public class UserMgmtService {
if (!Strings.isEmail(userEmail)) { if (!Strings.isEmail(userEmail)) {
throw new ServiceException(langPropsService.get("mailInvalidLabel")); throw new ServiceException(langPropsService.get("mailInvalidLabel"));
} }
final JSONObject duplicatedUser = userRepository.getByEmail(userEmail); final JSONObject duplicatedUser = userRepository.getByEmail(userEmail);
if (null != duplicatedUser) { if (null != duplicatedUser) {
......
...@@ -30,14 +30,14 @@ import org.testng.annotations.Test; ...@@ -30,14 +30,14 @@ import org.testng.annotations.Test;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://github.com/nanolikeyou">nanolikeyou</a> * @author <a href="https://github.com/nanolikeyou">nanolikeyou</a>
* @version 1.0.0.3, May 25, 2017 * @version 1.0.0.4, Aug 14, 2017
*/ */
@Test(suiteName = "service") @Test(suiteName = "service")
public class UserMgmtServiceTestCase extends AbstractTestCase { public class UserMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Add User. * Add User.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test @Test
...@@ -56,7 +56,7 @@ public class UserMgmtServiceTestCase extends AbstractTestCase { ...@@ -56,7 +56,7 @@ public class UserMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Update User. * Update User.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "addUser") @Test(dependsOnMethods = "addUser")
...@@ -64,7 +64,6 @@ public class UserMgmtServiceTestCase extends AbstractTestCase { ...@@ -64,7 +64,6 @@ public class UserMgmtServiceTestCase extends AbstractTestCase {
final UserMgmtService userMgmtService = getUserMgmtService(); final UserMgmtService userMgmtService = getUserMgmtService();
JSONObject requestJSONObject = new JSONObject(); JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_NAME, "user2name"); requestJSONObject.put(User.USER_NAME, "user2name");
requestJSONObject.put(User.USER_EMAIL, "test2@gmail.com"); requestJSONObject.put(User.USER_EMAIL, "test2@gmail.com");
requestJSONObject.put(User.USER_PASSWORD, "pass2"); requestJSONObject.put(User.USER_PASSWORD, "pass2");
...@@ -92,42 +91,38 @@ public class UserMgmtServiceTestCase extends AbstractTestCase { ...@@ -92,42 +91,38 @@ public class UserMgmtServiceTestCase extends AbstractTestCase {
Assert.assertEquals(getUserQueryService().getUser(id).getJSONObject( Assert.assertEquals(getUserQueryService().getUser(id).getJSONObject(
User.USER).getString(User.USER_PASSWORD), MD5.hash("pass2")); User.USER).getString(User.USER_PASSWORD), MD5.hash("pass2"));
} }
/** /**
* Valid User. * Valid User.
* *
*@throws Exception exception * @throws Exception exception
*/ */
@Test @Test
public void ValidUser() throws Exception { public void validUser() throws Exception {
final UserMgmtService userMgmtService = getUserMgmtService(); final UserMgmtService userMgmtService = getUserMgmtService();
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_NAME, "user1 name"); requestJSONObject.put(User.USER_NAME, "user1 name");
requestJSONObject.put(User.USER_EMAIL, "test1@gmail.com"); requestJSONObject.put(User.USER_EMAIL, "test1@gmail.com");
requestJSONObject.put(User.USER_PASSWORD, "pass1"); requestJSONObject.put(User.USER_PASSWORD, "pass1");
try { try {
final String id = userMgmtService.addUser(requestJSONObject); final String id = userMgmtService.addUser(requestJSONObject);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
Assert.assertTrue(e instanceof ServiceException); Assert.assertTrue(e instanceof ServiceException);
} }
} }
/** /**
* Vallid XSS username. * Valid XSS username.
* *
*@throws Exception exception * @throws Exception exception
*/ */
@Test(expectedExceptions = ServiceException.class) @Test(expectedExceptions = ServiceException.class)
public void XSSUser() throws Exception { public void XSSUser() throws Exception {
final UserMgmtService userMgmtService = getUserMgmtService(); final UserMgmtService userMgmtService = getUserMgmtService();
final JSONObject requestJSONObject = new JSONObject(); final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_NAME, "username"); requestJSONObject.put(User.USER_NAME, "username");
requestJSONObject.put(User.USER_EMAIL, "<script></script>"); requestJSONObject.put(User.USER_EMAIL, "<script></script>");
...@@ -136,20 +131,18 @@ public class UserMgmtServiceTestCase extends AbstractTestCase { ...@@ -136,20 +131,18 @@ public class UserMgmtServiceTestCase extends AbstractTestCase {
/** /**
* Remove User. * Remove User.
* *
* @throws Exception exception * @throws Exception exception
*/ */
@Test(dependsOnMethods = "addUser") @Test(dependsOnMethods = "addUser")
public void removeUser() throws Exception { public void removeUser() throws Exception {
final UserMgmtService userMgmtService = getUserMgmtService(); final UserMgmtService userMgmtService = getUserMgmtService();
final JSONObject user = final JSONObject user = getUserQueryService().getUserByEmail("test1@gmail.com");
getUserQueryService().getUserByEmail("test1@gmail.com");
Assert.assertNotNull(user); Assert.assertNotNull(user);
userMgmtService.removeUser(user.getString(Keys.OBJECT_ID)); userMgmtService.removeUser(user.getString(Keys.OBJECT_ID));
Assert.assertNull( Assert.assertNull(getUserQueryService().getUserByEmail("test1@gmail.com"));
getUserQueryService().getUserByEmail("test1@gmail.com"));
} }
} }
...@@ -27,7 +27,8 @@ import org.testng.annotations.Test; ...@@ -27,7 +27,8 @@ import org.testng.annotations.Test;
* {@link UserQueryService} test case. * {@link UserQueryService} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, May 16, 2012 * @author <a href="https://github.com/nanolikeyou">nanolikeyou</a>
* @version 1.0.0.2, Aug 14, 2017
*/ */
@Test(suiteName = "service") @Test(suiteName = "service")
public class UserQueryServiceTestCase extends AbstractTestCase { public class UserQueryServiceTestCase extends AbstractTestCase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment