### Question:
ChainedDeserializer { public Operand deserialize(JsonNode jsonNode, ObjectMapper objectMapper) throws JsonProcessingException { Deserializer deserializer = deserializers.stream() .filter(d -> d.isApplicable(jsonNode)) .findFirst() .orElseThrow(() -> new IllegalArgumentException(String.format("Node %s could not be deserialized to any known operand", jsonNode))); return deserializer.deserialize(jsonNode, objectMapper); } ChainedDeserializer(List<Deserializer> deserializers); Operand deserialize(JsonNode jsonNode, ObjectMapper objectMapper);  }### Answer:
@Test void shouldThrowExceptionWhenNoDeserializerSpecified() { JsonNode node = mock(JsonNode.class); when(node.toString()).thenReturn("{ TEST NODE }"); ChainedDeserializer deserializer = new ChainedDeserializer(Collections.emptyList()); assertThatThrownBy(() -> deserializer.deserialize(node, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Node { TEST NODE } could not be deserialized to any known operand"); }
@Test void shouldDeserializeWithFirstApplicableDeserializer() throws JsonProcessingException { JsonNode node = mock(JsonNode.class); Operand expected = mock(Operand.class); ChainedDeserializer deserializer = new ChainedDeserializer(Arrays.asList( new MockedDeserializer().withApplicable(true).withResult(expected), new MockedDeserializer().withApplicable(false) )); Operand result = deserializer.deserialize(node, null); assertThat(result).isEqualTo(expected); }
@Test void shouldDeserializeWithApplicableDeserializer() throws JsonProcessingException { JsonNode node = mock(JsonNode.class); Operand expected = mock(Operand.class); ChainedDeserializer deserializer = new ChainedDeserializer(Arrays.asList( new MockedDeserializer().withApplicable(false), new MockedDeserializer().withApplicable(true).withResult(expected) )); Operand result = deserializer.deserialize(node, null); assertThat(result).isEqualTo(expected); }
@Test void shouldThrowExceptionWhenNoApplicableDeserializer() { JsonNode node = mock(JsonNode.class); when(node.toString()).thenReturn("{ TEST NODE }"); ChainedDeserializer deserializer = new ChainedDeserializer(Arrays.asList( new MockedDeserializer().withApplicable(false), new MockedDeserializer().withApplicable(false) )); assertThatThrownBy(() -> deserializer.deserialize(node, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Node { TEST NODE } could not be deserialized to any known operand"); }