GetAdminServlet.java

1
package com.popx.presentazione;
2
3
import com.popx.modello.ProdottoBean;
4
import com.popx.persistenza.ProdottoDAO;
5
import com.popx.persistenza.ProdottoDAOImpl;
6
7
import javax.servlet.*;
8
import javax.servlet.http.*;
9
import javax.servlet.annotation.*;
10
import java.io.IOException;
11
import java.util.List;
12
13
@WebServlet(name = "GetAdminServlet", urlPatterns = {"/getAdminServlet"})
14
public class GetAdminServlet extends HttpServlet {
15
16
    private final ProdottoDAO prodottoDAO;
17
    private static final int PRODUCTS_PER_PAGE = 6;
18
19
    // �� production
20
    public GetAdminServlet() {
21
        this.prodottoDAO = new ProdottoDAOImpl();
22
    }
23
24
    // �� test
25
    public GetAdminServlet(ProdottoDAO prodottoDAO) {
26
        this.prodottoDAO = prodottoDAO;
27
    }
28
29
    @Override
30
    public void doGet(HttpServletRequest request, HttpServletResponse response)
31
            throws ServletException, IOException {
32
33
        List<ProdottoBean> prodotti;
34
35
        try {
36
            prodotti = prodottoDAO.getAllProducts();
37
        } catch (Exception e) {
38 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED
            response.sendError(
39
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
40
                    "Errore durante il recupero dei prodotti."
41
            );
42
            return;
43
        }
44
45 1 1. doGet : negated conditional → KILLED
        if (prodotti == null) {
46 1 1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED
            response.sendError(
47
                    HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
48
                    "Errore durante il recupero dei prodotti."
49
            );
50
            return;
51
        }
52
53
        int totalProducts = prodotti.size();
54 1 1. doGet : Replaced double division with multiplication → KILLED
        int totalPages = (int) Math.ceil((double) totalProducts / PRODUCTS_PER_PAGE);
55
56
        int currentPage = 1;
57
        String pageParam = request.getParameter("page");
58 1 1. doGet : negated conditional → SURVIVED
        if (pageParam != null) {
59
            try {
60
                currentPage = Integer.parseInt(pageParam);
61 2 1. doGet : changed conditional boundary → SURVIVED
2. doGet : negated conditional → SURVIVED
                if (currentPage < 1) currentPage = 1;
62
            } catch (NumberFormatException ignored) {
63
                currentPage = 1;
64
            }
65
        }
66
67 2 1. doGet : Replaced integer multiplication with division → SURVIVED
2. doGet : Replaced integer subtraction with addition → KILLED
        int start = (currentPage - 1) * PRODUCTS_PER_PAGE;
68 1 1. doGet : Replaced integer addition with subtraction → KILLED
        int end = Math.min(start + PRODUCTS_PER_PAGE, totalProducts);
69
70
        List<ProdottoBean> productsForPage = prodotti.subList(start, end);
71
72 1 1. doGet : removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED
        request.setAttribute("products", productsForPage);
73 1 1. doGet : removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED
        request.setAttribute("currentPage", currentPage);
74 1 1. doGet : removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED
        request.setAttribute("totalPages", totalPages);
75
76
        request.getRequestDispatcher("/jsp/DashboardAdmin.jsp")
77 1 1. doGet : removed call to javax/servlet/RequestDispatcher::forward → KILLED
                .forward(request, response);
78
    }
79
}

Mutations

38

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_exception_returns500()]
removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED

45

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_daoReturnsNull_returns500()]
negated conditional → KILLED

46

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_daoReturnsNull_returns500()]
removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED

54

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_success_firstPage()]
Replaced double division with multiplication → KILLED

58

1.1
Location : doGet
Killed by : none
negated conditional → SURVIVED

61

1.1
Location : doGet
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : doGet
Killed by : none
negated conditional → SURVIVED

67

1.1
Location : doGet
Killed by : none
Replaced integer multiplication with division → SURVIVED

2.2
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_invalidPage_defaultsToOne()]
Replaced integer subtraction with addition → KILLED

68

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_invalidPage_defaultsToOne()]
Replaced integer addition with subtraction → KILLED

72

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_success_firstPage()]
removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED

73

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_invalidPage_defaultsToOne()]
removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED

74

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_success_firstPage()]
removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED

77

1.1
Location : doGet
Killed by : com.popx.integration.presentazione.GetAdminServletTest.[engine:junit-jupiter]/[class:com.popx.integration.presentazione.GetAdminServletTest]/[method:getAdmin_invalidPage_defaultsToOne()]
removed call to javax/servlet/RequestDispatcher::forward → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.2