1 package com.atlassian.sal.core.features;
2
3 import org.junit.rules.TestWatcher;
4 import org.junit.runner.Description;
5
6 import javax.annotation.Nonnull;
7 import java.util.HashSet;
8 import java.util.Set;
9
10
11
12
13 public class ClearSystemPropertyRule extends TestWatcher
14 {
15 private final Set<String> properties = new HashSet<String>();
16
17
18
19
20
21
22 public void setProperty(@Nonnull final String key, @Nonnull final String value)
23 {
24 properties.add(key);
25 System.setProperty(key, value);
26 }
27
28
29
30
31
32
33
34
35 public void setPropertyWithDarkFeaturePrefix(@Nonnull final String key, @Nonnull final String value)
36 {
37 setProperty(DefaultDarkFeatureManager.ATLASSIAN_DARKFEATURE_PREFIX + key, value);
38 }
39
40 @Override
41 protected void finished(final Description description)
42 {
43 for (final String property : properties)
44 {
45 System.clearProperty(property);
46 }
47 }
48 }