IntentRequestHandler implements RequestHandler { @Override public boolean canHandle(HandlerInput input) { if (input.getRequestEnvelope().getRequest() instanceof IntentRequest) { IntentRequest request = (IntentRequest) input.getRequestEnvelope().getRequest(); return request.getIntent().getName().equals(intentName); } return false; } IntentRequestHandler(Class<T> intentClass, IntentMapper intentMapper);  IntentRequestHandler(Class<T> intentClass, IntentReader<T> intentReader); @Override boolean canHandle(HandlerInput input); @Override Optional<Response> handle(HandlerInput input);  }
@Test public void testCanHandleFalseIfMismatch() { TestIntentHandler underTest = new TestIntentHandler(mapper); when(mockInput.getRequestEnvelope()).thenReturn(RequestEnvelope.builder() .withRequest(IntentRequest.builder() .withIntent(com.amazon.ask.model.Intent.builder() .withName("NoMatch") .withSlots(Collections.emptyMap()) .build()) .build()) .build()); assertFalse(underTest.canHandle(mockInput)); }
@Test public void testCanHandleNameTrueIfMatches() { TestIntentHandler underTest = new TestIntentHandler(mapper); when(mockInput.getRequestEnvelope()).thenReturn(RequestEnvelope.builder() .withRequest(IntentRequest.builder() .withIntent(com.amazon.ask.model.Intent.builder() .withName("TestIntent") .withSlots(Collections.emptyMap()) .build()) .build()) .build()); assertTrue(underTest.canHandle(mockInput)); }