fix(io): idempotent MusicController.level; assert gain forwarding + shutdown
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,9 @@ public final class MusicController {
|
||||
|
||||
/** Applies a new music level (volume / off). */
|
||||
public void level(MusicLevel newLevel) {
|
||||
if (newLevel == this.level) {
|
||||
return;
|
||||
}
|
||||
this.level = newLevel;
|
||||
if (!newLevel.isOn()) {
|
||||
backend.fadeOut();
|
||||
|
||||
@@ -12,7 +12,8 @@ class MusicControllerTest {
|
||||
/** Records backend calls for assertions. */
|
||||
private static final class FakeBackend implements MusicBackend {
|
||||
final List<String> calls = new ArrayList<>();
|
||||
public void fadeTo(String track, float gainDb) { calls.add("fadeTo:" + track); }
|
||||
float lastGain = Float.NaN;
|
||||
public void fadeTo(String track, float gainDb) { calls.add("fadeTo:" + track); lastGain = gainDb; }
|
||||
public void fadeOut() { calls.add("fadeOut"); }
|
||||
public void setGainDb(float gainDb) { calls.add("setGain:" + gainDb); }
|
||||
public void shutdown() { calls.add("shutdown"); }
|
||||
@@ -84,4 +85,22 @@ class MusicControllerTest {
|
||||
c.room("a"); // current was reset → plays again
|
||||
assertThat(b.calls).containsExactly("fadeTo:a");
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardsTheCurrentLevelGain() {
|
||||
FakeBackend b = new FakeBackend();
|
||||
MusicController c = new MusicController(b);
|
||||
c.room("a");
|
||||
assertThat(b.lastGain).isEqualTo(MusicLevel.MEDIUM.gainDb());
|
||||
c.level(MusicLevel.HIGH);
|
||||
c.room("b");
|
||||
assertThat(b.lastGain).isEqualTo(MusicLevel.HIGH.gainDb());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shutdownDelegatesToBackend() {
|
||||
FakeBackend b = new FakeBackend();
|
||||
new MusicController(b).shutdown();
|
||||
assertThat(b.calls).containsExactly("shutdown");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user