Skip to content

Commit

Permalink
Configurable status bar color (#369)
Browse files Browse the repository at this point in the history
* added preference FAIL_BACKGROUND_COLOR

* added persistence for preference FAIL_BACKGROUND_COLOR

* added preference FAIL_BACKGROUND_COLOR to PreferencePage

* made VisualStatusPresenter use the configured value for FAIL_BACKGROUND_COLOR

* added preference FAIL_TEXT_COLOR

* made VisualStatusPresenter use FAIL_TEXT_COLOR

* added SWTColorFieldEditor for FAIL_TEXT_COLOR to PreferencePage

* added persistence for preference FAIL_TEXT_COLOR

* fixed failing test

* added missing license headers

* replaced usage of FailBackgroundColor and similar with FailingBackgroundColor and equivalents

* replaced usage of FailTextColor and similar with FailingTextColor and equivalents

* fix: minor issues detected by sonar

Co-authored-by: Jan Heyd <j.heyd@mailbox.tu-berlin.de>
  • Loading branch information
gtoison and jheyd authored Nov 11, 2022
1 parent 8564cd9 commit 9dff758
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

import static com.google.common.collect.Iterables.getOnlyElement;
import static java.util.Arrays.asList;
import static org.infinitest.eclipse.prefs.PreferencesConstants.FAILING_BACKGROUND_COLOR;
import static org.infinitest.eclipse.prefs.PreferencesConstants.FAILING_TEXT_COLOR;
import static org.infinitest.eclipse.prefs.PreferencesConstants.PARALLEL_CORES;
import static org.infinitest.eclipse.prefs.PreferencesConstants.SLOW_TEST_WARNING;
import static org.infinitest.util.InfinitestGlobalSettings.getSlowTestTimeLimit;
Expand All @@ -39,6 +41,8 @@
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.infinitest.eclipse.prefs.PreferencesConstants;
import org.infinitest.eclipse.trim.ColorSettings;
import org.infinitest.eclipse.workspace.CoreSettings;
import org.infinitest.util.InfinitestGlobalSettings;
import org.infinitest.util.InfinitestUtils;
Expand Down Expand Up @@ -96,6 +100,8 @@ public void startContinuouslyTesting() {
protected void initializeDefaultPreferences(IPreferenceStore store) {
store.setDefault(PARALLEL_CORES, 1);
store.setDefault(SLOW_TEST_WARNING, getSlowTestTimeLimit());
store.setDefault(FAILING_BACKGROUND_COLOR, ColorSettings.getFailingBackgroundColor());
store.setDefault(FAILING_TEXT_COLOR, ColorSettings.getFailingTextColor());
}

// Only used for testing.
Expand All @@ -116,7 +122,7 @@ public PluginActivationController getPluginController() {

public <T> T getBean(Class<T> beanClass) {
if (context == null) {
context = new AnnotationConfigApplicationContext(InfinitestConfig.class);
context = new AnnotationConfigApplicationContext(InfinitestConfig.class);

restoreSavedPreferences(getPluginPreferences(), getBean(CoreSettings.class));
InfinitestUtils.log(Level.FINE, "Beans loaded: " + asList(context.getBeanDefinitionNames()));
Expand All @@ -128,5 +134,7 @@ public <T> T getBean(Class<T> beanClass) {
void restoreSavedPreferences(Preferences preferences, CoreSettings coreSettings) {
coreSettings.setConcurrentCoreCount(preferences.getInt(PARALLEL_CORES));
InfinitestGlobalSettings.setSlowTestTimeLimit(preferences.getLong(SLOW_TEST_WARNING));
ColorSettings.setFailingBackgroundColor(preferences.getInt(PreferencesConstants.FAILING_BACKGROUND_COLOR));
ColorSettings.setFailngTextColor(preferences.getInt(PreferencesConstants.FAILING_TEXT_COLOR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.jface.util.*;
import org.infinitest.eclipse.*;
import org.infinitest.eclipse.markers.*;
import org.infinitest.eclipse.trim.*;
import org.infinitest.eclipse.workspace.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;
Expand Down Expand Up @@ -64,9 +65,21 @@ public void propertyChange(PropertyChangeEvent event) {
updateSlowTestWarning((String) newValue);
} else if (PARALLEL_CORES.equals(preference)) {
updateConcurrency((String) newValue);
} else if (PreferencesConstants.FAILING_BACKGROUND_COLOR.equals(preference)) {
updateFailingBackgroundColor((String) newValue);
} else if (PreferencesConstants.FAILING_TEXT_COLOR.equals(preference)) {
updateFailingTextColor((String) newValue);
}
}

private void updateFailingTextColor(String newValue) {
ColorSettings.setFailngTextColor(Integer.valueOf(newValue));
}

private void updateFailingBackgroundColor(String newValue) {
ColorSettings.setFailingBackgroundColor(Integer.valueOf(newValue));
}

private void updateConcurrency(String newValue) {
if (!isBlank(newValue)) {
coreSettings.setConcurrentCoreCount(Integer.parseInt(newValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,23 @@ private void initializePreferenceStoreToDefaultLocation() {

@Override
protected void createFieldEditors() {
BooleanFieldEditor autoTestEditor = new BooleanFieldEditor(AUTO_TEST, "Continuously Test", getFieldEditorParent());
addField(autoTestEditor);
addField(createAutoTestEditor());
addField(createParallelizationEditor());
addField(createSlowTestWarningCutoffEditor());
addField(createFailingBackgroundColorEditor());
addField(createFailingTextColorEditor());
}

private BooleanFieldEditor createAutoTestEditor() {
return new BooleanFieldEditor(AUTO_TEST, "Continuously Test", getFieldEditorParent());
}

private SwtColorFieldEditor createFailingBackgroundColorEditor() {
return new SwtColorFieldEditor(PreferencesConstants.FAILING_BACKGROUND_COLOR, "Fail Background Color", getFieldEditorParent());
}

private SwtColorFieldEditor createFailingTextColorEditor() {
return new SwtColorFieldEditor(PreferencesConstants.FAILING_TEXT_COLOR, "Fail Text Color", getFieldEditorParent());
}

private FieldEditor createSlowTestWarningCutoffEditor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ public abstract class PreferencesConstants {

public static final String SLOW_TEST_WARNING = "org.infinitest.eclipse.slow-warning";

public static final String FAILING_BACKGROUND_COLOR = "org.infinitest.eclipse.color.failing.background";

public static final String FAILING_TEXT_COLOR = "org.infinitest.eclipse.color.failing.text";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.infinitest.eclipse.prefs;

import org.eclipse.jface.preference.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

/*
* Infinitest, a Continuous Test Runner.
*
* Copyright (C) 2010-2013
* "Ben Rady" <benrady@gmail.com>,
* "Rod Coffin" <rfciii@gmail.com>,
* "Ryan Breidenbach" <ryan.breidenbach@gmail.com>
* "David Gageot" <david@gageot.net>, et al.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class SwtColorFieldEditor extends ComboFieldEditor {

private static final String[][] ENTRY_NAMES_AND_VALUES = {
{"Black", String.valueOf(SWT.COLOR_BLACK)},
{"Blue", String.valueOf(SWT.COLOR_BLUE )},
{"Blue (Dark)", String.valueOf(SWT.COLOR_DARK_BLUE)},
{"Cyan", String.valueOf(SWT.COLOR_CYAN)},
{"Cyan(Dark)", String.valueOf(SWT.COLOR_DARK_CYAN)},
{"Green", String.valueOf(SWT.COLOR_GREEN)},
{"Green (Dark)", String.valueOf(SWT.COLOR_DARK_GREEN)},
{"Gray", String.valueOf(SWT.COLOR_GRAY)},
{"Gray (Dark)", String.valueOf(SWT.COLOR_DARK_GRAY)},
{"Red", String.valueOf(SWT.COLOR_RED)},
{"Red (Dark)", String.valueOf(SWT.COLOR_DARK_RED)},
{"Magenta", String.valueOf(SWT.COLOR_MAGENTA)},
{"Magenta (Dark)", String.valueOf(SWT.COLOR_DARK_MAGENTA)},
{"Yellow", String.valueOf(SWT.COLOR_YELLOW)},
{"Yellow (Dark)", String.valueOf(SWT.COLOR_DARK_YELLOW)},
{"White", String.valueOf(SWT.COLOR_WHITE)},
};

public SwtColorFieldEditor(String name, String labelText, Composite parent) {
super(name, labelText, ENTRY_NAMES_AND_VALUES, parent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.infinitest.eclipse.trim;

import org.eclipse.swt.*;

/*
* Infinitest, a Continuous Test Runner.
*
* Copyright (C) 2010-2013
* "Ben Rady" <benrady@gmail.com>,
* "Rod Coffin" <rfciii@gmail.com>,
* "Ryan Breidenbach" <ryan.breidenbach@gmail.com>
* "David Gageot" <david@gageot.net>, et al.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class ColorSettings {
private static int failingBackgroundColor = SWT.COLOR_DARK_RED;
private static int failingTextColor = SWT.COLOR_WHITE;

private ColorSettings() {
}

public static int getFailingTextColor() {
return failingTextColor;
}

public static void setFailngTextColor(int failTextColor) {
ColorSettings.failingTextColor = failTextColor;
}

public static int getFailingBackgroundColor() {
return failingBackgroundColor;
}

public static void setFailingBackgroundColor(int failBackgroundColor) {
ColorSettings.failingBackgroundColor = failBackgroundColor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void testQueueUpdated(TestQueueEvent event) {
public void coreStatusChanged(CoreStatus oldStatus, CoreStatus newStatus) {
switch (newStatus) {
case PASSING:
status.setBackgroundColor(COLOR_DARK_GREEN);
status.setTextColor(COLOR_WHITE);
setPassingColors();
break;
case FAILING:
setFailingColors();
Expand All @@ -67,11 +66,16 @@ public void coreStatusChanged(CoreStatus oldStatus, CoreStatus newStatus) {
}
}

private void setFailingColors() {
status.setBackgroundColor(COLOR_DARK_RED);
private void setPassingColors() {
status.setBackgroundColor(COLOR_DARK_GREEN);
status.setTextColor(COLOR_WHITE);
}

private void setFailingColors() {
status.setBackgroundColor(ColorSettings.getFailingBackgroundColor());
status.setTextColor(ColorSettings.getFailingTextColor());
}

@Override
public void updateVisualStatus(VisualStatus status) {
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.mockito.Mockito.*;

import org.eclipse.core.runtime.*;
import org.infinitest.eclipse.trim.*;
import org.infinitest.eclipse.workspace.*;
import org.infinitest.util.*;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -54,10 +55,14 @@ void inContext() {
void shouldRestoreSavedPreferences() {
when(preferences.getInt(PARALLEL_CORES)).thenReturn(4);
when(preferences.getLong(SLOW_TEST_WARNING)).thenReturn(1000L);
when(preferences.getInt(FAILING_BACKGROUND_COLOR)).thenReturn(1);
when(preferences.getInt(FAILING_TEXT_COLOR)).thenReturn(2);

plugin.restoreSavedPreferences(preferences, coreSettings);

verify(coreSettings).setConcurrentCoreCount(4);
assertEquals(1000L, InfinitestGlobalSettings.getSlowTestTimeLimit());
assertEquals(1, ColorSettings.getFailingBackgroundColor());
assertEquals(2, ColorSettings.getFailingTextColor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@

import org.eclipse.jface.preference.*;
import org.eclipse.jface.util.*;
import org.eclipse.swt.*;
import org.infinitest.eclipse.*;
import org.infinitest.eclipse.markers.*;
import org.infinitest.eclipse.trim.*;
import org.infinitest.eclipse.workspace.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -92,6 +94,28 @@ void shouldAdjustWarningTimeout() {
assertEquals(100, getSlowTestTimeLimit());
}

@Test
void shouldAdjustFailingBackgroundColor() {
when(eventSource.getPreferenceName()).thenReturn(PreferencesConstants.FAILING_BACKGROUND_COLOR);
int red = SWT.COLOR_DARK_RED;
int blue = SWT.COLOR_BLUE;

changeProperty(SwtColorFieldEditor.VALUE, String.valueOf(red), String.valueOf(blue));

assertEquals(blue, ColorSettings.getFailingBackgroundColor());
}

@Test
void shouldAdjustFailingTextColor() {
when(eventSource.getPreferenceName()).thenReturn(PreferencesConstants.FAILING_TEXT_COLOR);
int white = SWT.COLOR_WHITE;
int yellow = SWT.COLOR_YELLOW;

changeProperty(SwtColorFieldEditor.VALUE, String.valueOf(white), String.valueOf(yellow));

assertEquals(yellow, ColorSettings.getFailingTextColor());
}

@Test
void shouldAdjustSemaphorePermits() {
when(eventSource.getPreferenceName()).thenReturn(PARALLEL_CORES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void shouldIgnoreUpdatesWhenStatusBarIsNotAttached() {
void shouldImmediatelySetStatusToFailingWhenATestFails() {
presenter.testCaseComplete(new TestCaseEvent("", null, new TestResults(methodFailed("", "", new AssertionError()))));

verify(statusBar).setBackgroundColor(COLOR_DARK_RED);
verify(statusBar).setTextColor(COLOR_WHITE);
verify(statusBar).setBackgroundColor(ColorSettings.getFailingBackgroundColor());
verify(statusBar).setTextColor(ColorSettings.getFailingTextColor());
}

@Test
Expand Down Expand Up @@ -122,11 +122,14 @@ void shouldChangeToGreenWhenTestsPass() {
}

@Test
void shouldChangeToRedWhenTestsFail() {
void shouldChangeToFailingBackgroundColorWhenTestsFail() {
ColorSettings.setFailingBackgroundColor(COLOR_DARK_RED);
ColorSettings.setFailngTextColor(COLOR_YELLOW);

presenter.coreStatusChanged(PASSING, FAILING);

verify(statusBar).setBackgroundColor(COLOR_DARK_RED);
verify(statusBar).setTextColor(COLOR_WHITE);
verify(statusBar).setTextColor(COLOR_YELLOW);
}

@Test
Expand Down

0 comments on commit 9dff758

Please sign in to comment.