• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

link-intersystems / lis-commons / #316

19 May 2024 06:41AM UTC coverage: 90.215% (+0.06%) from 90.156%
#316

push

renelink
Added AbstractProperty tests.

0 of 1 new or added line in 1 file covered. (0.0%)

7708 of 8544 relevant lines covered (90.22%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/lis-commons-beans/src/main/java/com/link_intersystems/beans/AbstractProperty.java
1
package com.link_intersystems.beans;
2

3

4
import java.util.Arrays;
5
import java.util.Objects;
6
import java.util.function.Supplier;
7

8
import static java.util.Objects.*;
9

10
public abstract class AbstractProperty implements Property {
11

12
    private final PropertyDesc propertyDescriptor;
13

14
    public AbstractProperty(PropertyDesc propertyDescriptor) {
1✔
15
        this.propertyDescriptor = requireNonNull(propertyDescriptor);
1✔
16
    }
1✔
17

18

19
    @Override
20
    public PropertyDesc getPropertyDesc() {
21
        return propertyDescriptor;
1✔
22
    }
23

24
    /**
25
     * Gets the value of this {@link AbstractProperty}.
26
     *
27
     * @return the value of this property.
28
     * @throws PropertyReadException if the property could not be accessed for any reason. If the
29
     *                               thrown {@link PropertyReadException} has no cause this property
30
     *                               is not readable (has no property getter method).
31
     * @since 1.2.0;
32
     */
33
    @Override
34
    public <T> T getValue() {
35
        PropertyDesc propertyDesc = getPropertyDesc();
1✔
36
        Object beanObject = getBeanObject();
1✔
37
        return propertyDesc.getPropertyValue(beanObject);
1✔
38
    }
39

40
    protected abstract Object getBeanObject();
41

42
    /**
43
     * Sets the value of this {@link AbstractProperty}.
44
     *
45
     * @param propertyValue the value to set.
46
     * @throws PropertyReadException if this {@link AbstractProperty}'s value could not be set. If the thrown
47
     *                               {@link PropertyWriteException} has no cause this property is not
48
     *                               writable (has no property setter method).
49
     * @since 1.2.0;
50
     */
51
    @Override
52
    public void setValue(Object propertyValue) {
53
        PropertyDesc propertyDesc = getPropertyDesc();
1✔
54
        Object beanObject = getBeanObject();
1✔
55
        propertyDesc.setPropertyValue(beanObject, propertyValue);
1✔
56
    }
1✔
57

58
    @Override
59
    public int hashCode() {
60
        final int prime = 31;
1✔
61
        int result = 1;
1✔
62
        result = prime * result + getPropertyDesc().hashCode();
1✔
63
        Object value = getValue();
1✔
64

65
        if (value != null) {
1✔
66
            Class<?> valueClass = value.getClass();
1✔
67
            if (valueClass.isArray()) {
1✔
68
                result = prime * result + Arrays.deepHashCode((Object[]) value);
1✔
69
            } else {
70
                result = prime * result + value.hashCode();
1✔
71
            }
72
        }
73

74
        return result;
1✔
75
    }
76

77
    @Override
78
    public boolean equals(Object obj) {
79
        if (this == obj)
1✔
80
            return true;
1✔
81
        if (obj == null)
1✔
82
            return false;
1✔
83
        if (getClass() != obj.getClass())
1✔
84
            return false;
1✔
85
        AbstractProperty other = (AbstractProperty) obj;
1✔
86
        if (!getPropertyDesc().equals(other.getPropertyDesc()))
1✔
87
            return false;
×
88

89
        Object value = getValue();
1✔
90
        if (value == null) {
1✔
91
            return other.getValue() == null;
1✔
92
        } else {
93
            Object otherValue = other.getValue();
1✔
94

95
            if (otherValue == null) {
1✔
96
                return false;
1✔
97
            }
98

99
            Class<?> valueClass = value.getClass();
1✔
100
            Class<?> otherValueClass = otherValue.getClass();
1✔
101
            if (valueClass.isArray() && otherValueClass.isArray()) {
1✔
102
                return Objects.deepEquals(value, otherValue);
1✔
103
            } else if (!valueClass.isArray() && !otherValueClass.isArray()) {
1✔
104
                return value.equals(otherValue);
1✔
105
            } else {
106
                return false;
1✔
107
            }
108
        }
109
    }
110

111
    @Override
112
    public String toString() {
NEW
113
        return "Property{" +
×
114
                "propertyDescriptor=" + propertyDescriptor +
115
                '}';
116
    }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc