SlotModelArgumentResolver implements ArgumentResolver { @Override public Optional<Object> resolve(ArgumentResolverContext input) { try { if (input.requestTypeEquals(IntentRequest.class)) { Optional<Slot> annotation = input.getMethodParameter().findAnnotation(Slot.class); if (annotation.isPresent()) { return Optional.of(intentMapper.parseIntentSlot((IntentRequest) input.unwrapRequest(), annotation.get().value())); } } } catch (IntentParseException e) { } return Optional.empty(); } SlotModelArgumentResolver(IntentMapper intentMapper); @Override Optional<Object> resolve(ArgumentResolverContext input);  }
@Test public void testSupportAndResolve() throws NoSuchMethodException { Method method = MappingsController.class.getMethod("handleModelSlot", MappingsController.PetType.class); MethodParameter methodParameter = new MethodParameter( method, 0, MappingsController.PetType.class, method.getParameterAnnotations()[0] ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("PetTypeIntentTwo", "pet", "DRAGON"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); assertEquals(MappingsController.PetType.DRAGON, resolver.resolve(input).get()); }
@Test public void testDoesntSupport() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, Map.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("PetTypeIntent2", "pet", "DRAGON"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); assertFalse(resolver.resolve(input).isPresent()); }