BacklightSwitch extends AppCompatImageButton { void setImageBasedOn(final int brightnessValue) { setImageResource(brightnessValue == BRIGHTNESS_MIN ? R.drawable.ic_backlight_off_toolbar : R.drawable.ic_backlight_on_toolbar); } BacklightSwitch(final Context context, final AttributeSet attrs);   }
@Test public void shouldSwitchToMinimalBrightnessWhenCurrentValueIsMoreThanMinimalOne() { val backlightSwitch = givenDefaultBacklightSwitch(); val settings = givenSettingsWithBrightnessValue(50); val controller = new BacklightSwitch.BacklightController(settings, backlightSwitch); controller.onClick(mock(View.class)); then(settings).should().enableManualBrightnessControl(); then(settings).should().setScreenBrightnessTo(BRIGHTNESS_MIN); then(backlightSwitch).should().setImageBasedOn(BRIGHTNESS_MIN); }
@Test public void shouldSwitchBrightnessToMaxValueIfCurrentIsMinimalAndPreviousStateIsNotPresent() { val backlightSwitch = givenDefaultBacklightSwitch(); val settings = givenSettingsWithBrightnessValue(BRIGHTNESS_MIN); val controller = new BacklightSwitch.BacklightController(settings, backlightSwitch); controller.onClick(mock(View.class)); then(settings).should().enableManualBrightnessControl(); then(settings).should().setScreenBrightnessTo(BRIGHTNESS_MAX); then(backlightSwitch).should().setImageBasedOn(BRIGHTNESS_MAX); }
@Test public void shouldSwitchBrightnessFromMinimalValueToPreviousStateWhenPresent() { val backlightSwitch = givenDefaultBacklightSwitch(); val settings = givenSettingsWithBrightnessValue(30); val controller = new BacklightSwitch.BacklightController(settings, backlightSwitch); controller.onClick(mock(View.class)); then(settings).should().setScreenBrightnessTo(BRIGHTNESS_MIN); controller.onClick(mock(View.class)); then(settings).should().setScreenBrightnessTo(30); then(backlightSwitch).should().setImageBasedOn(30); }