2015-12-28 135 views
0

從1.4.0版本開始, 「PropertyChange現在與Property分離,從propertyChange引用到具體屬性被替換爲propertyName String field」。如何訪問屬性?

什麼是1.4.0更改後訪問Property的替代方法?因爲我想在房產

回答

2

訪問 「looksLikeId」 你可以用下面的代碼片段做:

ManagedType managedType = (ManagedType)javers.getTypeMapping(Person.class); 
Property property = managedType.getProperty(propertyChange.getPropertyName()); 

完整的示例(常規):

def "should extract Property from PropertyChange"(){ 
    given: 
    def javers = JaversTestBuilder.newInstance() 

    when: 
    def diff = javers.compare(new Person('1','bob'), new Person('1','bobby')) 
    PropertyChange propertyChange = diff.changes[0] 

    ManagedType managedType = (ManagedType)javers.getTypeMapping(Person) 
    Property property = managedType.getProperty(propertyChange.propertyName) 

    then: 
    property.name == 'name' 
    !property.looksLikeId() 
} 

在1.4.1版本中,我將爲方便javers添加方便getProperty()方法:

Property property = javers.getProperty(propertyChange) 
+0

謝謝,它的工作原理 –