Skip to content

Commit

Permalink
Paused and Resumed events are now sent (as audio elements) to the bro…
Browse files Browse the repository at this point in the history
…wser.
  • Loading branch information
tedyoung committed May 1, 2024
1 parent c6bd254 commit 164ccef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public boolean hasTimerFor(EnsembleId ensembleId) {
public boolean isTimerRunningFor(EnsembleId ensembleId) {
requireTimerToExistFor(ensembleId);
return ensembleTimers
.get(ensembleId)
.state() == CountdownTimer.TimerState.RUNNING;
.get(ensembleId)
.state() == CountdownTimer.TimerState.RUNNING;
}

public void startTimerFor(EnsembleId ensembleId, Instant timeStarted) {
Expand Down Expand Up @@ -154,6 +154,7 @@ public void pauseTimerFor(EnsembleId ensembleId) {

ensembleTimer.pause();

broadcaster.sendEvent(EnsembleTimer.TimerEvent.PAUSED);
broadcaster.sendCurrentTimer(ensembleTimer);
}

Expand All @@ -162,6 +163,7 @@ public void resumeTimerFor(EnsembleId ensembleId) {

ensembleTimer.resume();

broadcaster.sendEvent(EnsembleTimer.TimerEvent.RESUMED);
broadcaster.sendCurrentTimer(ensembleTimer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void onTickWhileRunningBroadcastsCurrentTimerState() {
}

@Test
void onTimerPauseBroadcastsPauseState() {
void onTimerPauseBroadcastsPauseStateAndPausedEvent() {
BroadcastFixture fixture = createBroadcasterWithStartedEnsembleTimer(
458,
CountdownTimer.TimerState.PAUSED,
Expand All @@ -235,10 +235,11 @@ void onTimerPauseBroadcastsPauseState() {
fixture.ensembleTimerHolder().pauseTimerFor(EnsembleId.of(458));

fixture.mockBroadcaster().verifyTimerStateSent();
fixture.mockBroadcaster().verifyPausedEventSent();
}

@Test
void onTimerResumeBroadcastsRunningState() {
void onTimerResumeBroadcastsRunningStateAndSendsResumedEvent() {
BroadcastFixture fixture = createBroadcasterWithStartedEnsembleTimer(
218,
CountdownTimer.TimerState.RUNNING,
Expand All @@ -250,6 +251,7 @@ void onTimerResumeBroadcastsRunningState() {
fixture.ensembleTimerHolder().resumeTimerFor(EnsembleId.of(218));

fixture.mockBroadcaster().verifyTimerStateSent();
fixture.mockBroadcaster().verifyResumedEventSent();
}

@Test
Expand Down Expand Up @@ -364,6 +366,7 @@ void reset() {
lastState = null;
lastEnsembleId = null;
lastTimeRemaining = null;
lastEventSent = null;
}

private void verifyTimerStateSent() {
Expand All @@ -382,10 +385,22 @@ private void verifyTimerStateSent() {
}

public void verifyFinishedEventSent() {
verifyLastEventSent(EnsembleTimer.TimerEvent.FINISHED);
}

public void verifyPausedEventSent() {
verifyLastEventSent(EnsembleTimer.TimerEvent.PAUSED);
}

public void verifyResumedEventSent() {
verifyLastEventSent(EnsembleTimer.TimerEvent.RESUMED);
}

private void verifyLastEventSent(EnsembleTimer.TimerEvent timerEvent) {
assertThat(lastEventSent)
.as("Expected last sendEvent() to be called with FINISHED, but wasn't.")
.as("Expected last sendEvent() to be called with " + timerEvent + ", but wasn't.")
.isNotNull()
.isEqualByComparingTo(EnsembleTimer.TimerEvent.FINISHED);
.isEqualByComparingTo(timerEvent);
}
}
}
Expand Down

0 comments on commit 164ccef

Please sign in to comment.