Skip to content

Commit

Permalink
#2 회원 서비스 테스트 케이스 빠트려서 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seongbin9786 committed Nov 4, 2018
1 parent 58ea817 commit c3c9f0a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
25 changes: 22 additions & 3 deletions src/main/java/com/spomatch/users/DefaultUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private UserId getNextId() {
}

@Override
public User update(User toUpdate) {
public User updateUserInfo(User toUpdate) {

for (User user : registeredUsers) {
if (user.equals(toUpdate)) {
Expand All @@ -53,6 +53,19 @@ public User update(User toUpdate) {
throw new UserNotExistException();
}

@Override
public User updatePlayers(User toUpdate) {

for (User user : registeredUsers) {
if (user.equals(toUpdate)) {
user.setPlayers(toUpdate.getPlayers());
return user;
}
}

throw new UserNotExistException();
}

private User cloneUser(User toClone) {

User user = new User();
Expand All @@ -68,8 +81,14 @@ private User cloneUser(User toClone) {
}

@Override
public void cancel(User toCancel) {
registeredUsers.removeIf(user -> user.equals(toCancel));
public void cancel(UserId idToCancel) {

User toCancel = getById(idToCancel);

if (toCancel.getPlayerSize() > 0)
throw new PlayerExistWhenCancelMembershipException();

registeredUsers.removeIf(user -> user.getId().equals(idToCancel));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.spomatch.users;

/**
* 회원 탈퇴 시도 시 플레이어가 존재하는 경우 던져지는 예외
*
* @author Seongbin Kim
*/
public class PlayerExistWhenCancelMembershipException extends RuntimeException {

private static final long serialVersionUID = 5362410971263147389L;

public PlayerExistWhenCancelMembershipException() {
}

public PlayerExistWhenCancelMembershipException(String message) {
super(message);
}
}
1 change: 0 additions & 1 deletion src/main/java/com/spomatch/users/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public void removePlayerBySportsType(SportsType typeToRemove) {
}

public void updateUserInfo(User toUpdate) {

this.pw = toUpdate.pw;
this.preferredLocations = toUpdate.preferredLocations;
this.age = toUpdate.age;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/spomatch/users/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public interface UserService {

User register(User user);

User update(User registered);
User updateUserInfo(User toUpdate);

void cancel(User user);
User updatePlayers(User toUpdate);

void cancel(UserId idToCancel);

User getById(UserId id);

Expand Down
24 changes: 22 additions & 2 deletions src/test/java/com/spomatch/users/TestUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;

import com.spomatch.users.players.Player;
import com.spomatch.users.players.SoccerPlayer;

/**
* 유저 서비스의 도메인 규칙을 분석하여 서비스의 스펙을 정의하고, 테스트합니다.
*
Expand Down Expand Up @@ -119,7 +122,7 @@ public class TestUserService {
registered.setIdForLogin(newIdForLogin);
registered.setName(newName);

User updated = userService.update(registered);
User updated = userService.updateUserInfo(registered);

// then
assertEquals(newPassword, updated.getPw());
Expand All @@ -137,11 +140,28 @@ public class TestUserService {
User user = registerDummy();

// when
userService.cancel(user);
userService.cancel(user.getId());

userService.getById(user.getId());
}

// then
@Test(expected = PlayerExistWhenCancelMembershipException.class)
public void 회원은_탈퇴할_수_있다_플레이어가_있어서_실패() {

// given
User user = registerDummy();

Player soccerPlayer = new SoccerPlayer();

user.addPlayer(soccerPlayer);

userService.updatePlayers(user);

// when
userService.cancel(user.getId());
}

private User registerDummy() {
User toRegister = UserTests.createDummy();

Expand Down

0 comments on commit c3c9f0a

Please sign in to comment.