Skip to content

Commit 9c38ec3

Browse files
committed
test fixes
1 parent a2ebaf9 commit 9c38ec3

2 files changed

Lines changed: 7 additions & 36 deletions

File tree

bugsnag/src/main/java/com/bugsnag/BugsnagAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ public void setFeatureFlag(LogbackFeatureFlag flag) {
649649
* @param name the feature flag name to remove
650650
*/
651651
public void clearFeatureFlag(String name) {
652-
featureFlags.removeIf(flag -> flag.getName().equals(name));
652+
featureFlags.removeIf(flag -> flag.getName() != null && flag.getName().equals(name));
653653

654654
if (bugsnag != null) {
655655
bugsnag.clearFeatureFlag(name);

bugsnag/src/test/java/com/bugsnag/ConfigurationFeatureFlagTest.java

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,25 @@ public void setUp() {
2424
public void testAddFeatureFlag() {
2525
config.addFeatureFlag("flag1", "variant-a");
2626

27-
// Verify by creating a client and checking the flags are inherited
28-
Bugsnag bugsnag = new Bugsnag("api-key");
29-
bugsnag.getConfig().addFeatureFlag("flag1", "variant-a");
30-
31-
Report report = bugsnag.buildReport(new RuntimeException("Test"));
27+
// Verify the config has the flag
28+
Report report = new Report(config, new RuntimeException("Test"));
3229
List<FeatureFlag> flags = report.getFeatureFlags();
3330

3431
assertEquals(1, flags.size());
3532
assertEquals("flag1", flags.get(0).getName());
3633
assertEquals("variant-a", flags.get(0).getVariant());
37-
38-
bugsnag.close();
3934
}
4035

4136
@Test
4237
public void testAddFeatureFlagWithoutVariant() {
4338
config.addFeatureFlag("flag1");
4439

45-
Bugsnag bugsnag = new Bugsnag("api-key");
46-
bugsnag.getConfig().addFeatureFlag("flag1");
47-
48-
Report report = bugsnag.buildReport(new RuntimeException("Test"));
40+
Report report = new Report(config, new RuntimeException("Test"));
4941
List<FeatureFlag> flags = report.getFeatureFlags();
5042

5143
assertEquals(1, flags.size());
5244
assertEquals("flag1", flags.get(0).getName());
5345
assertEquals(null, flags.get(0).getVariant());
54-
55-
bugsnag.close();
5646
}
5747

5848
@Test
@@ -63,17 +53,12 @@ public void testAddFeatureFlags() {
6353

6454
config.addFeatureFlags(flagsToAdd);
6555

66-
Bugsnag bugsnag = new Bugsnag("api-key");
67-
bugsnag.getConfig().addFeatureFlags(flagsToAdd);
68-
69-
Report report = bugsnag.buildReport(new RuntimeException("Test"));
56+
Report report = new Report(config, new RuntimeException("Test"));
7057
List<FeatureFlag> flags = report.getFeatureFlags();
7158

7259
assertEquals(2, flags.size());
7360
assertEquals("flag1", flags.get(0).getName());
7461
assertEquals("flag2", flags.get(1).getName());
75-
76-
bugsnag.close();
7762
}
7863

7964
@Test
@@ -82,18 +67,11 @@ public void testClearFeatureFlag() {
8267
config.addFeatureFlag("flag2", "variant-b");
8368
config.clearFeatureFlag("flag1");
8469

85-
Bugsnag bugsnag = new Bugsnag("api-key");
86-
bugsnag.getConfig().addFeatureFlag("flag1", "variant-a");
87-
bugsnag.getConfig().addFeatureFlag("flag2", "variant-b");
88-
bugsnag.getConfig().clearFeatureFlag("flag1");
89-
90-
Report report = bugsnag.buildReport(new RuntimeException("Test"));
70+
Report report = new Report(config, new RuntimeException("Test"));
9171
List<FeatureFlag> flags = report.getFeatureFlags();
9272

9373
assertEquals(1, flags.size());
9474
assertEquals("flag2", flags.get(0).getName());
95-
96-
bugsnag.close();
9775
}
9876

9977
@Test
@@ -102,16 +80,9 @@ public void testClearFeatureFlags() {
10280
config.addFeatureFlag("flag2", "variant-b");
10381
config.clearFeatureFlags();
10482

105-
Bugsnag bugsnag = new Bugsnag("api-key");
106-
bugsnag.getConfig().addFeatureFlag("flag1", "variant-a");
107-
bugsnag.getConfig().addFeatureFlag("flag2", "variant-b");
108-
bugsnag.getConfig().clearFeatureFlags();
109-
110-
Report report = bugsnag.buildReport(new RuntimeException("Test"));
83+
Report report = new Report(config, new RuntimeException("Test"));
11184
List<FeatureFlag> flags = report.getFeatureFlags();
11285

11386
assertEquals(0, flags.size());
114-
115-
bugsnag.close();
11687
}
11788
}

0 commit comments

Comments
 (0)