@Test public void toObject_noAllProperties() { Map<String, Object> properties = new HashMap<>(); properties.put("age", 23); thrown.expect(IllegalStateException.class); thrown.expectMessage("The property \"name\" is not set."); mapper.toObject(properties); }
@Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.name = (String) properties.get("name"); if (object.name == null && !properties.containsKey("name")) { throw new IllegalStateException("The property \"name\" is not set."); } try { object.age = (int) properties.get("age"); } catch (NullPointerException e) { if (!properties.containsKey("age")) { throw new IllegalStateException("The property \"age\" is not set."); } throw new NullPointerException("The property \"age\" has the value null. It can't be set to a int."); } return object; }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.name = (String) properties.get("name"); if (object.name == null && !properties.containsKey("name")) { throw new IllegalStateException("The property \"name\" is not set."); } try { object.age = (int) properties.get("age"); } catch (NullPointerException e) { if (!properties.containsKey("age")) { throw new IllegalStateException("The property \"age\" is not set."); } throw new NullPointerException("The property \"age\" has the value null. It can't be set to a int."); } return object; } }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.name = (String) properties.get("name"); if (object.name == null && !properties.containsKey("name")) { throw new IllegalStateException("The property \"name\" is not set."); } try { object.age = (int) properties.get("age"); } catch (NullPointerException e) { if (!properties.containsKey("age")) { throw new IllegalStateException("The property \"age\" is not set."); } throw new NullPointerException("The property \"age\" has the value null. It can't be set to a int."); } return object; }  }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.name = (String) properties.get("name"); if (object.name == null && !properties.containsKey("name")) { throw new IllegalStateException("The property \"name\" is not set."); } try { object.age = (int) properties.get("age"); } catch (NullPointerException e) { if (!properties.containsKey("age")) { throw new IllegalStateException("The property \"age\" is not set."); } throw new NullPointerException("The property \"age\" has the value null. It can't be set to a int."); } return object; }  @Override Person toObject(Map<String, Object> properties); @Override Map<String, Object> toProperties(Person object); }
Person implements Mapper<Person> { @Override public Person toObject(Map<String, Object> properties) { final Person object = new Person(); object.name = (String) properties.get("name"); if (object.name == null && !properties.containsKey("name")) { throw new IllegalStateException("The property \"name\" is not set."); } try { object.age = (int) properties.get("age"); } catch (NullPointerException e) { if (!properties.containsKey("age")) { throw new IllegalStateException("The property \"age\" is not set."); } throw new NullPointerException("The property \"age\" has the value null. It can't be set to a int."); } return object; }  @Override Person toObject(Map<String, Object> properties); @Override Map<String, Object> toProperties(Person object);  }