ConversationsAnalyticsManager { void sendSuccessfulConversationsDisplayResponse(ConversationsResponse conversationResponse, ConversationsDisplayRequest conversationrequest) { if (conversationResponse instanceof ReviewResponse) { ReviewResponse reviewResponse = (ReviewResponse) conversationResponse; sendUgcImpressionEvent( reviewResponse.getResults(), BVEventValues.BVProductType.CONVERSATIONS_REVIEWS, BVEventValues.BVImpressionContentType.REVIEW); sendReviewsProductPageView(reviewResponse.getResults()); } else if (conversationResponse instanceof StoreReviewResponse) { StoreReviewResponse storeReviewResponse = (StoreReviewResponse) conversationResponse; sendUgcImpressionEvent( storeReviewResponse.getResults(), BVEventValues.BVProductType.CONVERSATIONS_REVIEWS, BVEventValues.BVImpressionContentType.STORE_REVIEW); } else if (conversationResponse instanceof BulkStoreResponse) { BulkStoreResponse bulkStoresResponse = (BulkStoreResponse) conversationResponse; sendUgcImpressionEventStores(bulkStoresResponse.getResults()); } else if (conversationResponse instanceof QuestionAndAnswerResponse) { QuestionAndAnswerResponse questionAndAnswerResponse = (QuestionAndAnswerResponse) conversationResponse; sendUgcImpressionEventQAndA(questionAndAnswerResponse.getResults()); sendQAndAProductPageView(questionAndAnswerResponse.getResults()); } else if (conversationResponse instanceof ProductDisplayPageResponse) { ProductDisplayPageResponse productDisplayPageResponse = (ProductDisplayPageResponse) conversationResponse; sendPdpProductPageView(productDisplayPageResponse.getResults()); } else if (conversationResponse instanceof AuthorsResponse) { AuthorsResponse authorsResponse = (AuthorsResponse) conversationResponse; sendUsedFeatureDisplayAuthors(authorsResponse); } else if (conversationResponse instanceof CommentsResponse) { CommentsResponse commentsResponse = (CommentsResponse) conversationResponse; sendUgcImpressionEvent( commentsResponse.getResults(), BVEventValues.BVProductType.CONVERSATIONS_REVIEWS, BVEventValues.BVImpressionContentType.COMMENT); } else if(conversationResponse instanceof ReviewHighlightsResponse){ ReviewHighlightsRequest reviewHighlightsRequest = (ReviewHighlightsRequest) conversationrequest; String productId = reviewHighlightsRequest.getProductId(); sendUsedFeatureEventReviewHighlights(productId); } } ConversationsAnalyticsManager(BVPixel bvPixel, String clientId); void sendUsedFeatureInViewEvent(String productId, String containerId, BVEventValues.BVProductType bvProductType); void sendUsedFeatureScrolledEvent(String productId, BVEventValues.BVProductType bvProductType);  }
@Test public void displayReviewsResponseShouldSendEvents() throws Exception { final BVPixel bvPixel = mock(BVPixel.class); final String clientId = "someClient"; ConversationsAnalyticsManager subject = new ConversationsAnalyticsManager(bvPixel, clientId); ReviewResponse reviewResponse = parseJsonResourceFile("reviews_all_reviews.json", ReviewResponse.class, gson); subject.sendSuccessfulConversationsDisplayResponse(reviewResponse, null); ArgumentCaptor<BVMobileAnalyticsEvent> eventArgumentCaptor = ArgumentCaptor.forClass(BVMobileAnalyticsEvent.class); ArgumentCaptor<String> clientIdArgCaptor = ArgumentCaptor.forClass(String.class); verify(bvPixel, atLeastOnce()).trackEventForClient(eventArgumentCaptor.capture(), clientIdArgCaptor.capture()); List<BVMobileAnalyticsEvent> events = eventArgumentCaptor.getAllValues(); int impressionEventCount = 0; int pageViewEventCount = 0; for (BVMobileAnalyticsEvent event : events) { event.setBvMobileParams(stubData.getBvMobileParams()); if (event instanceof BVImpressionEvent) { impressionEventCount++; } else if (event instanceof BVPageViewEvent) { pageViewEventCount++; } } assertEquals(10, impressionEventCount); assertEquals(1, pageViewEventCount); String capturedClientId = clientIdArgCaptor.getValue(); assertEquals(clientId, capturedClientId); }