1212import io .split .grammar .Treatments ;
1313import io .split .telemetry .storage .InMemoryTelemetryStorage ;
1414import io .split .telemetry .storage .TelemetryStorage ;
15+ import org .junit .Before ;
1516import org .junit .Test ;
1617import org .mockito .Mockito ;
1718
2526import static org .hamcrest .Matchers .is ;
2627import static org .hamcrest .Matchers .nullValue ;
2728import static org .junit .Assert .assertThat ;
28- import static org .mockito .Mockito .mock ;
29- import static org .mockito .Mockito .when ;
29+ import static org .mockito .Mockito .*;
3030
3131public class SplitManagerImplTest {
3232
3333 private SplitClientConfig config = SplitClientConfig .builder ().setBlockUntilReadyTimeout (100 ).build ();
34- private static final TelemetryStorage TELEMETRY_STORAGE = Mockito .mock (InMemoryTelemetryStorage .class );
34+ private static TelemetryStorage TELEMETRY_STORAGE = Mockito .mock (InMemoryTelemetryStorage .class );
3535
36+ @ Before
37+ public void updateTelemetryStorage () {
38+ TELEMETRY_STORAGE = Mockito .mock (InMemoryTelemetryStorage .class );
39+ }
3640 @ Test
3741 public void splitCallWithNonExistentSplit () {
3842 String nonExistent = "nonExistent" ;
@@ -95,23 +99,28 @@ public void splitCallWithExistentSplitAndConfigs() {
9599 public void splitsCallWithNoSplit () {
96100 SplitCache splitCache = Mockito .mock (SplitCache .class );
97101 Mockito .when (splitCache .getAll ()).thenReturn (Lists .<ParsedSplit >newArrayList ());
102+ SDKReadinessGates gates = Mockito .mock (SDKReadinessGates .class );
103+ Mockito .when (gates .isSDKReadyNow ()).thenReturn (false );
98104 SplitManagerImpl splitManager = new SplitManagerImpl (splitCache ,
99105 Mockito .mock (SplitClientConfig .class ),
100- Mockito . mock ( SDKReadinessGates . class ) , TELEMETRY_STORAGE );
106+ gates , TELEMETRY_STORAGE );
101107 assertThat (splitManager .splits (), is (empty ()));
108+ verify (TELEMETRY_STORAGE , times (1 )).recordNonReadyUsage ();
102109 }
103110
104111 @ Test
105112 public void splitsCallWithSplit () {
106113 SplitCache splitCache = Mockito .mock (SplitCache .class );
107114 List <ParsedSplit > parsedSplits = Lists .newArrayList ();
115+ SDKReadinessGates gates = Mockito .mock (SDKReadinessGates .class );
116+ Mockito .when (gates .isSDKReadyNow ()).thenReturn (false );
108117 ParsedSplit response = ParsedSplit .createParsedSplitForTests ("FeatureName" , 123 , true , "off" , Lists .newArrayList (getTestCondition ("off" )), "traffic" , 456L , 1 );
109118 parsedSplits .add (response );
110119
111120 Mockito .when (splitCache .getAll ()).thenReturn (parsedSplits );
112121 SplitManagerImpl splitManager = new SplitManagerImpl (splitCache ,
113122 Mockito .mock (SplitClientConfig .class ),
114- Mockito . mock ( SDKReadinessGates . class ) , TELEMETRY_STORAGE );
123+ gates , TELEMETRY_STORAGE );
115124 List <SplitView > splits = splitManager .splits ();
116125 assertThat (splits .size (), is (equalTo (1 )));
117126 assertThat (splits .get (0 ).name , is (equalTo (response .feature ())));
@@ -120,16 +129,20 @@ public void splitsCallWithSplit() {
120129 assertThat (splits .get (0 ).trafficType , is (equalTo (response .trafficTypeName ())));
121130 assertThat (splits .get (0 ).treatments .size (), is (equalTo (1 )));
122131 assertThat (splits .get (0 ).treatments .get (0 ), is (equalTo ("off" )));
132+ verify (TELEMETRY_STORAGE , times (1 )).recordNonReadyUsage ();
123133 }
124134
125135 @ Test
126136 public void splitNamesCallWithNoSplit () {
127137 SplitCache splitCache = Mockito .mock (SplitCache .class );
128138 Mockito .when (splitCache .getAll ()).thenReturn (Lists .<ParsedSplit >newArrayList ());
139+ SDKReadinessGates gates = Mockito .mock (SDKReadinessGates .class );
140+ Mockito .when (gates .isSDKReadyNow ()).thenReturn (false );
129141 SplitManagerImpl splitManager = new SplitManagerImpl (splitCache ,
130142 Mockito .mock (SplitClientConfig .class ),
131- Mockito . mock ( SDKReadinessGates . class ) , TELEMETRY_STORAGE );
143+ gates , TELEMETRY_STORAGE );
132144 assertThat (splitManager .splitNames (), is (empty ()));
145+ verify (TELEMETRY_STORAGE , times (1 )).recordNonReadyUsage ();
133146 }
134147
135148 @ Test
@@ -169,6 +182,7 @@ public void block_until_ready_times_when_sdk_is_not_ready() throws TimeoutExcept
169182 ready , TELEMETRY_STORAGE );
170183
171184 splitManager .blockUntilReady ();
185+ verify (TELEMETRY_STORAGE , times (1 )).recordBURTimeout ();
172186 }
173187
174188 private ParsedCondition getTestCondition (String treatment ) {
0 commit comments