-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...om/thirdparty/ticketing/global/waitingsystem/memory/running/MemoryRunningCounterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.thirdparty.ticketing.global.waitingsystem.memory.running; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MemoryRunningCounterTest { | ||
|
||
private MemoryRunningCounter runningCounter; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
runningCounter = new MemoryRunningCounter(new ConcurrentHashMap<>()); | ||
} | ||
|
||
@Nested | ||
@DisplayName("카운터 증가 호출 시") | ||
class IncrementTest { | ||
|
||
@Test | ||
@DisplayName("주어진 값만큼 값을 증가시킨다.") | ||
void increment() { | ||
// given | ||
long performanceId = 1; | ||
int number = 10; | ||
|
||
// when | ||
runningCounter.increment(performanceId, number); | ||
|
||
// then | ||
long runningCount = runningCounter.getRunningCounter(performanceId); | ||
assertThat(runningCount).isEqualTo(number); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
|
@@ -100,4 +103,35 @@ void getAvailableToRunning(int membersCount, int expectAvailableToRunning) { | |
assertThat(availableToRunning).isEqualTo(expectAvailableToRunning); | ||
} | ||
} | ||
|
||
@Nested | ||
@DisplayName("작업 가능 공간 입장 호출 시") | ||
class EnterTest { | ||
|
||
@Test | ||
@DisplayName("사용자의 이메일 정보를 작업 가능 공간에 넣는다.") | ||
void putEmailInfo() { | ||
// given | ||
long performanceId = 1; | ||
Set<WaitingMember> waitingMembers = new HashSet<>(); | ||
for (int i = 0; i < 10; i++) { | ||
waitingMembers.add( | ||
new WaitingMember( | ||
"email" + i + "@email.com", performanceId, i, ZonedDateTime.now())); | ||
} | ||
|
||
// when | ||
runningRoom.enter(performanceId, waitingMembers); | ||
|
||
// then | ||
String[] emails = | ||
waitingMembers.stream().map(WaitingMember::getEmail).toArray(String[]::new); | ||
// 각 이메일이 runningRoom 에 존재하는지 확인 | ||
for (String email : emails) { | ||
assertThat(runningRoom.contains(email, performanceId)).isTrue(); | ||
} | ||
// 존재하지 않는 이메일은 false 를 반환하는지 확인 | ||
assertThat(runningRoom.contains("[email protected]", performanceId)).isFalse(); | ||
} | ||
} | ||
} |