### Question:
NotificationRouter { @TransactionAttribute(TransactionAttributeType.REQUIRED) public void submit(PushApplication pushApplication, InternalUnifiedPushMessage message) { logger.debug("Processing send request with '{}' payload", message.getMessage()); final VariantMap variants = new VariantMap(); final List<String> variantIDs = message.getCriteria().getVariants(); if (variantIDs != null) { variantIDs.forEach(variantID -> { Variant variant = genericVariantService.get().findByVariantID(variantID); if (variant != null) { variants.add(variant); } }); } else { variants.addAll(pushApplication.getVariants()); } String jsonMessageContent = message.toStrippedJsonString() ; if (jsonMessageContent != null && jsonMessageContent.length() >= 4500) { jsonMessageContent = message.toMinimizedJsonString(); } final FlatPushMessageInformation pushMessageInformation = metricsService.storeNewRequestFrom( pushApplication.getPushApplicationID(), jsonMessageContent, message.getIpAddress(), message.getClientIdentifier() ); variants.forEach((variantType, variant) -> { logger.info(String.format("Internal dispatching of push message for one %s variant (by %s)", variantType.getTypeName(), message.getClientIdentifier())); dispatchVariantMessageEvent.fire(new MessageHolderWithVariants(pushMessageInformation, message, variantType, variant)); }); }  @TransactionAttribute(TransactionAttributeType.REQUIRED) void submit(PushApplication pushApplication, InternalUnifiedPushMessage message);  }### Answer:
@Test public void testNoVariants() { countDownLatch = new CountDownLatch(1); assertTrue("variants are empty", app.getVariants().isEmpty()); router.submit(app, message); assertEquals(variants(), variantTypeHolder.getVariantTypes()); }
@Test public void testTwoVariantsOfSameType() throws InterruptedException { countDownLatch = new CountDownLatch(1); app.getVariants().add(new AndroidVariant()); app.getVariants().add(new AndroidVariant()); router.submit(app, message); countDownLatch.await(3, TimeUnit.SECONDS); assertEquals(variants(VariantType.ANDROID), variantTypeHolder.getVariantTypes()); }
@Test public void testThreeVariantsOfDifferentType() throws InterruptedException { countDownLatch = new CountDownLatch(3); app.getVariants().add(new AndroidVariant()); app.getVariants().add(new iOSVariant()); router.submit(app, message); countDownLatch.await(3, TimeUnit.SECONDS); assertEquals(variants(VariantType.ANDROID, VariantType.IOS), variantTypeHolder.getVariantTypes()); }
@Test public void testInvokesMetricsService(FlatPushMessageInformationDao pushMessageInformationDao) { router.submit(app, message); verify(pushMessageInformationDao).create(Mockito.any(FlatPushMessageInformation.class)); }
@Test public void testVariantIDsSpecified(GenericVariantService genericVariantService) throws InterruptedException { countDownLatch = new CountDownLatch(2); iOSVariant iOSVariant = new iOSVariant(); iOSVariant.setId("id-ios-variant"); AndroidVariant androidVariant = new AndroidVariant(); androidVariant.setId("id-android-variant"); app.getVariants().addAll(Arrays.asList(iOSVariant, androidVariant)); message.getCriteria().setVariants(Arrays.asList("id-ios-variant", "id-android-variant")); when(genericVariantService.findByVariantID("id-ios-variant")).thenReturn(iOSVariant); when(genericVariantService.findByVariantID("id-android-variant")).thenReturn(androidVariant); router.submit(app, message); countDownLatch.await(3, TimeUnit.SECONDS); assertEquals(variants(VariantType.ANDROID, VariantType.IOS), variantTypeHolder.getVariantTypes()); }