File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
main/java/software/aws/solution/clickstream
test/java/software/aws/solution/clickstream Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,9 @@ public void enable() {
9090 @ Override
9191 public void recordEvent (@ NonNull String eventName ) {
9292 final AnalyticsEvent event = analyticsClient .createEvent (eventName );
93- analyticsClient .recordEvent (event );
93+ if (event != null ) {
94+ analyticsClient .recordEvent (event );
95+ }
9496 }
9597
9698 @ Override
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ public void testRecordEventWithName() throws Exception {
130130 assertEquals (0 , dbUtil .getTotalNumber ());
131131 }
132132
133+ /**
134+ * test record event with invalid name.
135+ *
136+ * @throws Exception exception
137+ */
138+ @ Test
139+ public void testRecordEventWithInvalidName () throws Exception {
140+ executeBackground ();
141+ ClickstreamAnalytics .recordEvent ("01TestEvent" );
142+ try (Cursor cursor = dbUtil .queryAllEvents ()) {
143+ cursor .moveToFirst ();
144+ String eventString = cursor .getString (2 );
145+ JSONObject jsonObject = new JSONObject (eventString );
146+ assertEquals (Event .PresetEvent .CLICKSTREAM_ERROR , jsonObject .getString ("event_type" ));
147+ }
148+ assertEquals (1 , dbUtil .getTotalNumber ());
149+ Thread .sleep (1500 );
150+ assertEquals (0 , dbUtil .getTotalNumber ());
151+ }
152+
133153 /**
134154 * test record one AnalyticsEvent use ClickstreamAnalytics api and
135155 * make sure the event data is valid from db.
You can’t perform that action at this time.
0 commit comments