Praveen
Praveen

Reputation: 11

How can I write Junit test cases for @AllArgsConstructor in lombok

How can write the test cases for @AllArgsConstructor in lombok. Can any help me out solving the problem.

@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class ABC{
    private Integer A;
    private String B;
    private BigDecimal c;
    private BigDecimal d;
    private String e;
    private String f;
    private String g;
}

Upvotes: 0

Views: 1814

Answers (1)

Feel free
Feel free

Reputation: 1069

Creating an instance with all args will make a thing:

public class ABCTest {
    
        @Test
        public void testAllArgsConstructor() {
        ABC abc = new ABC(1, "test", new BigDecimal("10.5"), new 
        BigDecimal("20.5"), "example", "sample", "data");
        assertNotNull(abc);
    
        }
    }

Or create variables for each value:

public class ABCTest {

    @Test
    public void testAllArgsConstructor() {
        Integer a = 1;
        String b = "test";
        BigDecimal c = new BigDecimal("10.5");
        BigDecimal d = new BigDecimal("20.5");
        String e = "example";
        String f = "sample";
        String g = "data";

        ABC abc = new ABC(a, b, c, d, e, f, g);

        assertNotNull(abc);

    }
}

If you add get methods you will be able to check equals adding to test like:

assertEquals(a, abc.getA());
assertEquals(b, abc.getB());
assertEquals(c, abc.getC());
assertEquals(d, abc.getD());
assertEquals(e, abc.getE());
assertEquals(f, abc.getF());
assertEquals(g, abc.getG()); 

Upvotes: 1

Related Questions