Menu

Showing posts with label JUnit for getter and setter. Show all posts
Showing posts with label JUnit for getter and setter. Show all posts

JUnit for Java getter and setter methods

 

POJO class

public class ColleagueDetails {
private String colleagueID;
private String colleagueEmail;
public ColleagueDetails(String colleagueID, String colleagueEmail) {
this.colleagueID = colleagueID;
this.colleagueEmail = colleagueEmail;
}
public String getColleagueID() { return colleagueID; }
public void setColleagueID(String colleagueID) { this.colleagueID = colleagueID; }
public String getColleagueEmail() { return colleagueEmail; }
public void setColleagueEmail(String colleagueEmail) { this.colleagueEmail = colleagueEmail; }
}

Test class
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

class ColleagueDetailsTest {
ColleagueDetails colleagueDetails = new ColleagueDetails("1234", "email@jorvee.com");

@BeforeEach
void setUp() { }

@Test
void getColleagueIDTest() {
colleagueDetails.setColleagueID("1234");
assertEquals("1234", colleagueDetails.getColleagueID());
}

@Test
void getColleagueEmailTest() {
colleagueDetails.setColleagueEmail("email@jorvee.com");
assertEquals("email@jorvee.com", colleagueDetails.getColleagueEmail());
}

}