### Question:
UserImageFactory { public List<UserImage> from(final Object data) { if (!(data instanceof Map<?, ?>)) { throw new IllegalArgumentException( String.format("Unexpected data format :: %s", String.valueOf(data))); } @SuppressWarnings("unchecked") final Map<Object, Object> entries = (Map<Object, Object>) data; return entries .entrySet() .stream() .map(entry -> { if (!(entry.getKey() instanceof String)) { throw new IllegalArgumentException( String.format("Unexpected data format :: %s", String.valueOf(entry.getKey()))); } if (!(entry.getValue() instanceof Object[])) { throw new IllegalArgumentException( String.format("Unexpected data format :: %s", String.valueOf(entry.getValue()))); } final Object[] values = (Object[]) entry.getValue(); if (values.length != 2) { throw new IllegalArgumentException(String.format( "Unexpected array length :: expected=2, actual=%d", values.length)); } if (!(values[1] instanceof String)) { throw new IllegalArgumentException( String.format("Unexpected data format :: %s", String.valueOf(values[1]))); } return UserImage.builder() .hash((String) entry.getKey()) .url((String) values[1]) .build(); }) .collect(Collectors.toList()); }  List<UserImage> from(final Object data);  }### Answer:
@Test public void fromTest() { final List<UserImage> expected = List.of( UserImage.builder() .hash("foo") .url("https: .build() ); final Map<String, Object[]> data = Map.of( "foo", new Object[]{0, "https: ); final List<UserImage> actual = userImageFactory.from(data); assertEquals(expected, actual); }
@Test public void fromNonMapTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format :: "); userImageFactory.from(Collections.<Integer>emptyList()); }
@Test @SuppressWarnings("ConstantConditions") public void fromNullTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format :: null"); userImageFactory.from(null); }
@Test public void fromInvalidKeyTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format ::"); userImageFactory.from(Map.of(1, new Object[]{0, "foo"})); }
@Test public void fromInvalidValueTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format ::"); userImageFactory.from(Map.of("foo", true)); }
@Test public void fromNullValueTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format ::"); final Map<String, Object> data = Maps.newHashMap(); data.put("foo", null); userImageFactory.from(data); }
@Test public void fromInvalidValueLengthTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected array length :: expected=2, actual=0"); userImageFactory.from(Map.of("foo", new Object[]{})); }
@Test public void fromInvalidValueTypeTest() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Unexpected data format :: "); userImageFactory.from(Map.of("foo", new Object[]{0, 1})); }