DistinguishedNameEditor extends PropertyEditorSupport { public void setAsText(String text) throws IllegalArgumentException { if (text == null) { setValue(null); } else { setValue(new DistinguishedName(text).immutableDistinguishedName()); } }  void setAsText(String text); String getAsText();  }
@Test public void testSetAsText() throws Exception { String expectedDn = "dc=jayway, dc=se"; tested.setAsText(expectedDn); DistinguishedName result = (DistinguishedName) tested.getValue(); assertThat(result).isEqualTo(new DistinguishedName(expectedDn)); try { result.getNames().add(new LdapRdn("cn", "john doe")); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { assertThat(true).isTrue(); } }
@Test public void testSetAsTextNullValue() throws Exception { tested.setAsText(null); Object result = tested.getValue(); assertThat(result).isNull(); }