Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks weird, you should run ./gradlew spotlessApply.

Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
package com.codedifferently.lesson15;

public class Employee {
private int id;
private String name;
private String department;
private double salary;

public Employee(int id, String name, String department, double salary) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete this code? This is the code you're supposed to test.

this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
}

// Getters and setters
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}
import com.google.common.annotations.VisibleForTesting;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need to use this.


public void setName(String name) {
this.name = name;
}

public String getDepartment() {
return department;
}

public void setDepartment(String department) {
this.department = department;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
public class Employee {
private static final String Details = null;
private int id;
private String name;
private String department;
private double salary;

public Employee(int id, String name, String department, double salary) {
this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
}

public void testGetDetails() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test code belongs in a test file, not here.

Employee employee = new Employee(id, "Will Smith", department, 101);
String expected = "Employee Name: Will Smith, id: 101:";
String actual = employee.getDetails();

assertEquals(expected, actual);
}

private void assertEquals(String expected, String actual) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'assertEquals'");
}

public String getDetails() {
return Details;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on formatting.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codedifferently.lesson15;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

Expand All @@ -12,8 +13,109 @@ public void testLesson15() {
}

@Test
public void testGetGreeting() {
// Act
Lesson15.main(null);
public void employee_getID() {
// Arrange
int expectID = 12345;
Employee employee = new Employee(expectID, null, null, 0);

// Act
int actualID = employee.getId();

// Assert
assertEquals(expectID, actualID);
}

@Test
public void employee_setID() {
// Arrange
int expectID = 12345;
Employee employee = new Employee(expectID, "Will Smith", "Producing", expectID);

// Act
int actualID = employee.setID();

// Assert
assertEquals(expectID, actualID);

}

@Test
public void getName() {
// Arrange
Employee employee = new Employee(12345, "Will Smith", null, 100000);

// Act
String expected = "Will Smith";

// Assert
String actual = employee.getName();
assertEquals(expected, actual);
}

@Test
public void setName() {
//Arrange
Employee employee = new Employee(12345, "Will Smith", null, 100000);

// Act
String expected = "Will Smith";

// Assert
String actual = employee.getName();
assertEquals(expected, actual);
}

@Test
public void getDepartment() {
//Arrange
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);

// Act
String expected = "Producing";

//Assert
String actual = employee.getDepartment();
assertEquals(expected, actual);
}

@Test
public void setDepartment() {
//Arrange
Employee employee = new Employee(12345, "Will Smith", "Producing", 0);

// Act
String expected = "Producing";

// Assert
String actual = employee.getDepartment();
assertEquals(expected, actual);
}

@Test
public void getSalary() {
// Arrange
Employee employee = new Employee(12345, "Will Smith", "Producing", 50000);

// Act
Short actual = null;
Short expected = null;

// Assert
assertEquals(expected, actual);
}

@Test
public void setSalary(double salary) {
//Arrange
Employee employee = new Employee(12345, "Will Smith", "Producing", 100000);

// Act
int actualId = employee.setSalary();

Short expected = null;
Short actual = null;
// Assert
assertEquals(expected, actual);
}

}
Loading