Skip to content

Commit 83214c1

Browse files
authored
fix - Show what's new is always true (#1128)
1 parent 3fc9e83 commit 83214c1

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.microsoft.copilot.eclipse.ui.preferences;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.eclipse.core.runtime.preferences.ConfigurationScope;
7+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
import com.microsoft.copilot.eclipse.core.Constants;
12+
13+
/**
14+
* Test cases for CopilotPreferenceInitializer.
15+
*/
16+
class CopilotPreferenceInitializerTest {
17+
18+
private CopilotPreferenceInitializer initializer;
19+
private IEclipsePreferences configPrefs;
20+
21+
@BeforeEach
22+
void setUp() {
23+
initializer = new CopilotPreferenceInitializer();
24+
configPrefs = ConfigurationScope.INSTANCE.getNode(Constants.PLUGIN_ID);
25+
26+
// Clean up any existing preference to ensure clean test state
27+
configPrefs.remove(Constants.AUTO_SHOW_WHAT_IS_NEW);
28+
}
29+
30+
@Test
31+
void testInitializeDefaultPreferences_WhenAutoShowWhatsNewNotSet_ShouldSetToTrue() {
32+
initializer.initializeDefaultPreferences();
33+
34+
boolean autoShowWhatsNew = configPrefs.getBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, false);
35+
assertTrue(autoShowWhatsNew);
36+
}
37+
38+
@Test
39+
void testInitializeDefaultPreferences_WhenAutoShowWhatsNewSetToFalse_ShouldRemainFalse() {
40+
configPrefs.putBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, false);
41+
42+
initializer.initializeDefaultPreferences();
43+
44+
boolean autoShowWhatsNew = configPrefs.getBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, true);
45+
assertFalse(autoShowWhatsNew);
46+
}
47+
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CopilotPreferenceInitializer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public void initializeDefaultPreferences() {
4747
""");
4848
pref.setDefault(Constants.MCP_TOOLS_STATUS, "{}");
4949

50-
IEclipsePreferences configPref = ConfigurationScope.INSTANCE.getNode(Constants.PLUGIN_ID);
51-
configPref.putBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, true);
50+
IEclipsePreferences configPrefs = ConfigurationScope.INSTANCE.getNode(Constants.PLUGIN_ID);
51+
String autoShowWhatsNew = configPrefs.get(Constants.AUTO_SHOW_WHAT_IS_NEW, null);
52+
if (autoShowWhatsNew == null) {
53+
configPrefs.putBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, true);
54+
}
5255
}
5356
}

0 commit comments

Comments
 (0)