IntentRenderer { public Intent renderIntent(IntentDefinition intentDefinition, IntentData intentData) { List<Slot> slots = intentDefinition.getSlots().entrySet().stream() .map(s -> intentSlotRenderer.renderSlot(s.getKey(), s.getValue(), intentData)) .collect(Collectors.toList()); return Intent.builder() .withName(intentDefinition.getName()) .withSlots(slots.isEmpty() ? null : slots) .withSamples(intentData.getSamples().isEmpty() ? null : new ArrayList<>(intentData.getSamples())) .build(); } IntentRenderer(IntentSlotRenderer intentSlotRenderer);  IntentRenderer(); Intent renderIntent(IntentDefinition intentDefinition, IntentData intentData); Optional<DialogIntent> renderDialogIntent(IntentDefinition intentDefinition, IntentData intentData); List<Prompt> renderPrompts(IntentDefinition intentDefinition, IntentData intentData);  }
@Test public void testRenderIntent_NoSlots() { IntentDefinition intent = IntentDefinition.builder() .withName("TestIntent") .withCustom(false) .withIntentType(Mockito.mock(JavaType.class)) .build(); IntentData intentData = IntentData.builder().build(); Intent expected = Intent.builder() .withName("TestIntent") .build(); Intent actual = underTest.renderIntent(intent, intentData); assertEquals(expected, actual); }
@Test public void testRenderIntent_Slots() { IntentData intentData = IntentData.builder() .addSlot("slot_name", IntentSlotData.builder().build()) .build(); Intent expected = Intent.builder() .withName("TestIntent") .withSlots(Collections.singletonList(Slot.builder() .withName("slot_name") .withType("slot_type") .build())) .build(); Intent actual = underTest.renderIntent(intent, intentData); assertEquals(expected, actual); }
@Test public void testRenderIntent_Samples() { IntentData intentData = IntentData.builder() .addSlot("slot_name", IntentSlotData.builder().build()) .addSample("test") .build(); Intent expected = Intent.builder() .withName("TestIntent") .withSlots(Collections.singletonList(Slot.builder() .withName("slot_name") .withType("slot_type") .build())) .withSamples(Collections.singletonList("test")) .build(); Intent actual = underTest.renderIntent(intent, intentData); assertEquals(expected, actual); }