Example usage for org.springframework.beans NotWritablePropertyException getPropertyName

List of usage examples for org.springframework.beans NotWritablePropertyException getPropertyName

Introduction

In this page you can find the example usage for org.springframework.beans NotWritablePropertyException getPropertyName.

Prototype

public String getPropertyName() 

Source Link

Document

Return the name of the offending property.

Usage

From source file:org.springframework.beans.AbstractPropertyAccessorTests.java

@Test
public void setUnknownProperty() {
    Simple target = new Simple("John", 2);
    AbstractPropertyAccessor accessor = createAccessor(target);

    try {/*from   w w w .j  a va  2 s .  co  m*/
        accessor.setPropertyValue("name1", "value");
        fail("Should have failed to set an unknown property.");
    } catch (NotWritablePropertyException e) {
        assertEquals(Simple.class, e.getBeanClass());
        assertEquals("name1", e.getPropertyName());
        assertEquals("Invalid number of possible matches", 1, e.getPossibleMatches().length);
        assertEquals("name", e.getPossibleMatches()[0]);
    }
}

From source file:org.springframework.beans.AbstractPropertyAccessorTests.java

@Test
public void setUnknownPropertyWithPossibleMatches() {
    Simple target = new Simple("John", 2);
    AbstractPropertyAccessor accessor = createAccessor(target);

    try {/* w w  w  .  j a va2  s  .c  o m*/
        accessor.setPropertyValue("foo", "value");
        fail("Should have failed to set an unknown property.");
    } catch (NotWritablePropertyException e) {
        assertEquals(Simple.class, e.getBeanClass());
        assertEquals("foo", e.getPropertyName());
    }
}