Commit 5d576b07 authored by Lakshmi Chaitanya's avatar Lakshmi Chaitanya

First commit

parents
# Default ignored files
/shelf/
/workspace.xml
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.2'
testRuntimeOnly('org.junit.jupiter:junit-jupiter-params:5.8.2')
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.mockito:mockito-core:4.3.1'
testImplementation 'org.mockito:mockito-junit-jupiter:4.3.1'
}
test {
useJUnitPlatform()
}
\ No newline at end of file
public class Employee {
private String firstName;
private String lastName;
private String dob;
private String address1;
private String address2;
private String city;
private String state;
private int postalCode;
public Employee(String firstName, String lastName, String dob, String address1, String address2, String city, String state, int postalCode) {
this.firstName = firstName;
this.lastName = lastName;
this.dob = dob;
this.address1 = address1;
this.address2 = address2;
this.city = city;
this.state = state;
this.postalCode = postalCode;
}
public Employee() {
}
public Employee addEmployee() {
return new Employee("Lakshmi", "chaitanya", "08/10/1985", "9400 w parmer", "9401 w parmer", "Austin", "Tx", 73526);
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public int getPostalCode() {
return postalCode;
}
public void setPostalCode(int postalCode) {
this.postalCode = postalCode;
}
}
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class EmployeeMocitoTest {
@Mock
Employee employee;
@Test
void testGetLastName() {
when(employee.getLastName()).thenReturn("mockLastName");
assertEquals("mockLastName", employee.getLastName());
}
@Test
void testAddEmployee() {
when(employee.addEmployee())
.thenReturn(new Employee("pavani", "ravuri", "08/10/1985", "9400 w parmer", "9401 w parmer", "Austin", "Tx", 10000));
assertNotEquals(73526, employee.addEmployee().getPostalCode());
}
}
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumingThat;
public class EmployeeTest {
Employee employee = null;
@BeforeEach
void setup() {
employee = new Employee();
}
@ParameterizedTest
@CsvFileSource(resources = "/EmployeeTestData.csv")
public void testGetFirstName(String firstName, String lastName, String dob, String addressLine1,
String addressLine2, String city, String state, int postalCode) {
this.employee = new Employee(firstName, lastName, dob, addressLine1,
addressLine2, city, state, postalCode);
assertAll(
() -> assertNotNull(employee),
() -> assertEquals(firstName, employee.getFirstName()),
() -> assertEquals(lastName, employee.getLastName()),
() -> assertEquals(dob, employee.getDob()),
() -> assertEquals(addressLine1, employee.getAddress1()),
() -> assertEquals(addressLine2, employee.getAddress2()),
() -> assertEquals(city, employee.getCity()),
() -> assertEquals(state, employee.getState()),
() -> assertEquals(postalCode, employee.getPostalCode())
);
}
@Test
public void assumingThatEmployeeTest() {
assumingThat(employee == null,
() -> assertTrue(employee.getFirstName() != null, "assumingThatTest - Failed"));
assertFalse(employee.getFirstName() != null, "assumingThatTest - Failed");
}
}
Lakshmi,chaitanya,08/10/1985,9400 w parmer,9401 w parmer, Austin,Tx,73526
pavani,ravuri,08/16/1982,9401 w parmer,9406 w parmer, San Ramon, Ca,73516
Suresh,nuthki,05/12/1987,9402 w parmer,9407 w parmer,Charlotte, Nc,73536
Kishore,rachagulla,04/16/1989,9403 w parmer,9408 w parmer, Denver, Co,73546
Revathi,venkata,08/10/1983,9404 w parmer,9409 w parmer, Dallas, Tx,73556
Saahithi,rachagulla,03/10/1988,9405 w parmer,9405 w parmer, San Antonio, Tx,73566
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment