resolved conflicts

This commit is contained in:
Karan Khanna 2018-06-07 21:29:38 +02:00
parent 8080f07c6c
commit 11ae9c438c
3 changed files with 11 additions and 20 deletions

View File

@ -5,9 +5,9 @@ public class Employee {
private int id;
private String name;
private String department;
private Double salary;
private long salary;
public Employee(int id, String name, String department, Double salary) {
public Employee(int id, String name, String department, long salary) {
super();
this.id = id;
this.name = name;
@ -61,11 +61,11 @@ public class Employee {
this.department = department;
}
public Double getSalary() {
public long getSalary() {
return salary;
}
public void setSalary(Double salary) {
public void setSalary(long salary) {
this.salary = salary;
}

View File

@ -14,18 +14,15 @@ import com.google.gson.Gson;
@WebServlet(name = "EmployeeServlet", urlPatterns = "/employeeServlet")
public class EmployeeServlet extends HttpServlet {
private Gson gson = new Gson();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String department = request.getParameter("department");
Double salary = Double.parseDouble(request.getParameter("salary"));
Employee employee = new Employee(id, name, department, salary);
String employeeJsonString = new Gson().toJson(employee);
Employee employee = new Employee(1, "Karan", "IT", 5000);
String employeeJsonString = this.gson.toJson(employee);
PrintWriter out = response.getWriter();
response.setContentType("application/json");

View File

@ -36,21 +36,15 @@ public class EmployeeServletIntegrationTest {
int id = 1;
String name = "Karan Khanna";
String department = "IT";
Double salary = 5000.0;
long salary = 5000;
employee = new Employee(id, name, department, salary);
//when
when(httpServletRequest.getParameter("id")).thenReturn(String.valueOf(id));
when(httpServletRequest.getParameter("name")).thenReturn(name);
when(httpServletRequest.getParameter("department")).thenReturn(department);
when(httpServletRequest.getParameter("salary")).thenReturn(String.valueOf(salary));
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
when(httpServletResponse.getWriter()).thenReturn(pw);
EmployeeServlet employeeServlet = new EmployeeServlet();
employeeServlet.doPost(httpServletRequest, httpServletResponse);
employeeServlet.doGet(httpServletRequest, httpServletResponse);
String employeeJsonString = sw.getBuffer().toString().trim();
Employee fetchedEmployee = new Gson().fromJson(employeeJsonString, Employee.class);