mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2026-03-21 23:16:02 +00:00
#3248 Refactor enum mapping for more refactoring safety
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
package de.danoeh.antennapod.core.feed;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class VolumeReductionSettingTest {
|
||||
|
||||
@Test
|
||||
public void mapOffToInteger() {
|
||||
VolumeReductionSetting setting = VolumeReductionSetting.OFF;
|
||||
assertThat(setting.toInteger(), is(equalTo(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapLightToInteger() {
|
||||
VolumeReductionSetting setting = VolumeReductionSetting.LIGHT;
|
||||
|
||||
assertThat(setting.toInteger(), is(equalTo(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapHeavyToInteger() {
|
||||
VolumeReductionSetting setting = VolumeReductionSetting.HEAVY;
|
||||
|
||||
assertThat(setting.toInteger(), is(equalTo(2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapIntegerToVolumeReductionSetting() {
|
||||
assertThat(VolumeReductionSetting.fromInteger(0), is(equalTo(VolumeReductionSetting.OFF)));
|
||||
assertThat(VolumeReductionSetting.fromInteger(1), is(equalTo(VolumeReductionSetting.LIGHT)));
|
||||
assertThat(VolumeReductionSetting.fromInteger(2), is(equalTo(VolumeReductionSetting.HEAVY)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void cannotMapNegativeValues() {
|
||||
VolumeReductionSetting.fromInteger(-1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void cannotMapValuesOutOfRange() {
|
||||
VolumeReductionSetting.fromInteger(3);
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package de.danoeh.antennapod.core.service.playback;
|
||||
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -13,7 +14,7 @@ public class FeedVolumeReductionTest {
|
||||
@Test
|
||||
public void noReductionIfTurnedOff() {
|
||||
FeedPreferences feedPreferences = mock(FeedPreferences.class);
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(FeedPreferences.VolumeReductionSetting.OFF);
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(VolumeReductionSetting.OFF);
|
||||
|
||||
FeedVolumeReduction feedVolumeReduction = new FeedVolumeReduction();
|
||||
float reductionFactor = feedVolumeReduction.getReductionFactor(feedPreferences);
|
||||
@ -25,10 +26,10 @@ public class FeedVolumeReductionTest {
|
||||
FeedPreferences feedPreferences = mock(FeedPreferences.class);
|
||||
FeedVolumeReduction feedVolumeReduction = new FeedVolumeReduction();
|
||||
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(FeedPreferences.VolumeReductionSetting.LIGHT);
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(VolumeReductionSetting.LIGHT);
|
||||
float lightReductionFactor = feedVolumeReduction.getReductionFactor(feedPreferences);
|
||||
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(FeedPreferences.VolumeReductionSetting.HEAVY);
|
||||
when(feedPreferences.getVolumeReductionSetting()).thenReturn(VolumeReductionSetting.HEAVY);
|
||||
float heavyReductionFactor = feedVolumeReduction.getReductionFactor(feedPreferences);
|
||||
|
||||
assertTrue("Light reduction must have higher factor than heavy reduction", lightReductionFactor > heavyReductionFactor);
|
||||
|
||||
@ -4,7 +4,7 @@ import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences.VolumeReductionSetting;
|
||||
import de.danoeh.antennapod.core.feed.VolumeReductionSetting;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user