Cloud Stack Ninja

I am struggling to write/understand a unit test for JPA inheritance @idClass in Intellij IDE. When running the test with code coverage, the IDE displays 5/6 method covered. But the class has only five methods. Where is the 6th method? What am I missing?

package com.beetlehand.model;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "product_attribute", schema = "beetlehand", catalog = "")
@IdClass(ProductAttributeEntityPK.class)
public class ProductAttributeEntity {
    private int productId;
    private int attributeValueId;

    /*** Getters and Setters ***/

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ProductAttributeEntity that = (ProductAttributeEntity) o;
        return productId == that.productId &&
                attributeValueId == that.attributeValueId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(productId, attributeValueId);
    }
}

And the unit test

package com.beetlehand.model;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class ProductAttributeEntityPKTest {
    @Test
    void testGetProductId() {
        ProductAttributeEntity entity = new ProductAttributeEntity();
        entity.setProductId(1);
        entity.setAttributeValueId(1);

        assertEquals(1, entity.getProductId());
    }
    @Test
    void testGetAttributeValueId() {
        /*** test logic ***/

        assertEquals(1, entity.getAttributeValueId());
    }
    @Test
    void testEquals() {
        /*** test logic ***/

        assertEquals(true, entity.equals(entity2));
    }
    @Test
    void testHashCode() {
        /*** test logic ***/

        assertEquals(entity2.hashCode(), entity.hashCode());
    }
}


Read more here: https://stackoverflow.com/questions/64393874/how-to-unit-test-jpa-idclass

Content Attribution

This content was originally published by dobby at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: