IntentModelArgumentResolver implements ArgumentResolver { @Override public Optional<Object> resolve(ArgumentResolverContext input) { try { if (input.requestTypeEquals(IntentRequest.class)) { Object model = intentMapper.parseIntent((IntentRequest) input.unwrapRequest()); if (input.getMethodParameter().getType().isInstance(model)) { return Optional.of(model); } } } catch (IntentParseException e) { } return Optional.empty(); } IntentModelArgumentResolver(IntentMapper intentMapper); @Override Optional<Object> resolve(ArgumentResolverContext input);  }
@Test public void testSupportAndResolve() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, MappingsController.PetTypeIntent.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("PetTypeIntent", "pet", "DRAGON"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); Object resolved = resolver.resolve(input).get(); assertTrue(resolved instanceof MappingsController.PetTypeIntent); }
@Test public void testDoesntSupport() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, Map.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("PetTypeIntent", "pet", "DRAGON"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); Optional<Object> result = resolver.resolve(input); assertFalse(result.isPresent()); }
@Test public void testSupportsParentClass() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, Object.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("PetTypeIntent", "pet", "DRAGON"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); assertTrue(resolver.resolve(input).isPresent()); }