2525
2626#import < XCTest/XCTest.h>
2727#import " LPCountAggregator.h"
28+ #import " Constants.h"
2829
2930/* *
3031 * Expose private class methods
@@ -33,6 +34,9 @@ @interface LPCountAggregator(UnitTest)
3334
3435@property (nonatomic , strong ) NSMutableDictionary *counts;
3536
37+ - (NSDictionary *)getAndClearCounts ;
38+ - (NSMutableDictionary *)makeParams : (nonnull NSString *)name withCount : (int ) count ;
39+
3640@end
3741
3842@interface LPCountAggregatorTest : XCTestCase
@@ -96,4 +100,32 @@ - (void)test_incrementCountMultiple {
96100 XCTAssert ([countAggregator.counts[testString] intValue ] == 17 );
97101}
98102
103+ - (void )test_getAndClearCounts {
104+ LPCountAggregator *countAggregator = [[LPCountAggregator alloc ] init ];
105+ NSString *testString = @" test" ;
106+ NSString *testString2 = @" test2" ;
107+ countAggregator.enabledCounters = [NSSet setWithObjects: testString, testString2, nil ];
108+
109+ [countAggregator incrementCount: testString by: 2 ];
110+ [countAggregator incrementCount: testString2 by: 15 ];
111+
112+ NSDictionary *previousCounts = [countAggregator getAndClearCounts ];
113+
114+ // test counts is empty after clearing
115+ XCTAssert ([countAggregator.counts count ] == 0 );
116+ // test counts transferred to previousCounts
117+ XCTAssert ([previousCounts[testString] intValue ] == 2 );
118+ XCTAssert ([previousCounts[testString2] intValue ] == 15 );
119+ }
120+
121+ - (void )test_makeParams {
122+ LPCountAggregator *countAggregator = [[LPCountAggregator alloc ] init ];
123+ NSString *testString = @" test" ;
124+ NSMutableDictionary *params = [countAggregator makeParams: testString withCount: 2 ];
125+
126+ XCTAssert ([params[LP_PARAM_TYPE] isEqualToString: @" SDK_COUNT" ]);
127+ XCTAssert ([params[LP_PARAM_MESSAGE] isEqualToString: testString]);
128+ XCTAssert ([params[LP_PARAM_COUNT] intValue ] == 2 );
129+ }
130+
99131@end
0 commit comments