2
2
3
3
import static com .lightstep .tracer .shared .LightStepConstants .Tags .COMPONENT_NAME_KEY ;
4
4
import static com .lightstep .tracer .shared .LightStepConstants .Tags .GUID_KEY ;
5
- import static com .lightstep .tracer .shared .LightStepConstants .Tags .LEGACY_COMPONENT_NAME_KEY ;
6
5
import static com .lightstep .tracer .shared .LightStepConstants .Collector .DEFAULT_PLAINTEXT_PORT ;
7
6
import static com .lightstep .tracer .shared .LightStepConstants .Collector .DEFAULT_SECURE_PORT ;
8
7
import static com .lightstep .tracer .shared .LightStepConstants .Collector .PATH ;
18
17
import static org .junit .Assert .assertNull ;
19
18
import static org .junit .Assert .assertSame ;
20
19
import static org .junit .Assert .assertTrue ;
20
+ import static org .mockito .ArgumentMatchers .anyString ;
21
21
22
- import io .opentracing .ScopeManager ;
23
22
import io .opentracing .propagation .Format .Builtin ;
24
- import io .opentracing .propagation .TextMap ;
25
23
import io .opentracing .util .ThreadLocalScopeManager ;
26
24
import java .net .InetAddress ;
27
25
import java .util .Collections ;
30
28
import com .lightstep .tracer .shared .Options .OkHttpDns ;
31
29
32
30
import org .junit .Test ;
33
-
31
+ import org .junit .runner .RunWith ;
32
+ import org .mockito .Mockito ;
33
+ import org .mockito .invocation .InvocationOnMock ;
34
+ import org .mockito .stubbing .Answer ;
35
+ import org .powermock .api .mockito .PowerMockito ;
36
+ import org .powermock .core .classloader .annotations .PrepareForTest ;
37
+ import org .powermock .modules .junit4 .PowerMockRunner ;
38
+
39
+ @ RunWith (PowerMockRunner .class )
40
+ @ PrepareForTest ({Options .class })
34
41
public class OptionsTest {
35
42
private static final String ACCESS_TOKEN = "my-access-token" ;
36
43
private static final String SERVICE_VERSION = "v0.1.0" ;
@@ -51,6 +58,17 @@ public List<InetAddress> lookup(String hostname) {
51
58
}
52
59
};
53
60
61
+ private void mockSystem () {
62
+ PowerMockito .mockStatic (System .class );
63
+ Mockito .when (System .getProperty (anyString (), anyString ())).thenAnswer (
64
+ new Answer <String >() {
65
+ @ Override
66
+ public String answer (InvocationOnMock invocationOnMock ) {
67
+ return invocationOnMock .getArgument (1 );
68
+ }
69
+ });
70
+ }
71
+
54
72
/**
55
73
* Basic test of OptionsBuilder that ensures if I set everything explicitly, that these values
56
74
* are propagated to the Options object.
@@ -256,6 +274,42 @@ public void testOptionsBuilder_defaultDisableMetricsReporting() throws Exception
256
274
assertFalse (options .disableMetricsReporting );
257
275
}
258
276
277
+ @ Test
278
+ public void testOptionsBuilder_disableMetricsReporting_fromEnvVariable_True () throws Exception {
279
+ mockSystem ();
280
+ Mockito .when (System .getenv (LightStepConstants .Metrics .LS_METRICS_ENABLED ))
281
+ .thenReturn ("true" );
282
+
283
+ Options options = new Options .OptionsBuilder ()
284
+ .build ();
285
+
286
+ assertFalse (options .disableMetricsReporting );
287
+ }
288
+
289
+ @ Test
290
+ public void testOptionsBuilder_disableMetricsReporting_fromEnvVariable_False () throws Exception {
291
+ mockSystem ();
292
+ Mockito .when (System .getenv (LightStepConstants .Metrics .LS_METRICS_ENABLED ))
293
+ .thenReturn ("false" );
294
+
295
+ Options options = new Options .OptionsBuilder ()
296
+ .build ();
297
+
298
+ assertTrue (options .disableMetricsReporting );
299
+ }
300
+
301
+ @ Test
302
+ public void testOptionsBuilder_disableMetricsReporting_fromEnvVariable_NotBoolean () throws Exception {
303
+ mockSystem ();
304
+ Mockito .when (System .getenv (LightStepConstants .Metrics .LS_METRICS_ENABLED ))
305
+ .thenReturn ("not-boolean" );
306
+
307
+ Options options = new Options .OptionsBuilder ()
308
+ .build ();
309
+
310
+ assertFalse (options .disableMetricsReporting );
311
+ }
312
+
259
313
@ Test
260
314
public void testOptionsBuilder_hostname_notSet () throws Exception {
261
315
Options options = new Options .OptionsBuilder ().build ();
0 commit comments