LocaleArgumentResolver implements ArgumentResolver { @Override public Optional<Object> resolve(ArgumentResolverContext input) { if (input.parameterTypeEquals(Locale.class)) { return Optional.of(Locale.forLanguageTag(input.unwrapRequest().getLocale())); } return Optional.empty(); }  @Override Optional<Object> resolve(ArgumentResolverContext input);  }
@Test public void testDoesntSupport() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, Object.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = Utils.buildSimpleEnvelope("intent"); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); assertFalse(resolver.resolve(input).isPresent()); }
@Test public void testSupportAndResolve() throws NoSuchMethodException { MethodParameter methodParameter = new MethodParameter( this.getClass().getMethod("testSupportAndResolve"), 0, Locale.class, MethodParameter.EMPTY_ANNOTATIONS ); RequestEnvelope envelope = RequestEnvelope.builder() .withRequest( LaunchRequest.builder() .withLocale("ja-JP") .build() ) .build(); ArgumentResolverContext input = new ArgumentResolverContext(mockSkillContext, methodParameter, HandlerInput.builder().withRequestEnvelope(envelope).build()); assertEquals(Locale.JAPAN, resolver.resolve(input).get()); }