org.codemucker.jtest.bean.tester.hashcodeequals.TstBeanBrokenCtor.java Source code

Java tutorial

Introduction

Here is the source code for org.codemucker.jtest.bean.tester.hashcodeequals.TstBeanBrokenCtor.java

Source

/*
 * Copyright 2011 Bert van Brakel
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.codemucker.jtest.bean.tester.hashcodeequals;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.codemucker.jpattern.bean.Property;

public class TstBeanBrokenCtor {
    private String fieldA;
    private String fieldB;

    public TstBeanBrokenCtor() {

    }

    public TstBeanBrokenCtor(@Property(name = "fieldA") String fieldA, @Property(name = "fieldB") String fieldB) {
        super();
        this.fieldA = fieldA;
        // broken assignment we are testing
        this.fieldB = fieldA;
    }

    public String getFieldA() {
        return fieldA;
    }

    public void setFieldA(String fieldA) {
        this.fieldA = fieldA;
    }

    public String getFieldB() {
        return fieldB;
    }

    public void setFieldB(String fieldB) {
        this.fieldB = fieldB;
    }

    @Override
    public boolean equals(Object other) {
        return EqualsBuilder.reflectionEquals(this, other);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(17, 7, this);
    }

}