DataSourceSingleton.java

1
package com.popx.persistenza;
2
3
import javax.naming.Context;
4
import javax.naming.InitialContext;
5
import javax.naming.NamingException;
6
import javax.sql.DataSource;
7
8
public class DataSourceSingleton {
9
    private static volatile DataSource instance;
10
11
    private DataSourceSingleton() {}
12
13
    public static DataSource getInstance() {
14 1 1. getInstance : negated conditional → KILLED
        if (instance == null) {
15
            synchronized (DataSourceSingleton.class) {
16 1 1. getInstance : negated conditional → NO_COVERAGE
                if (instance == null) {
17
                    try {
18
                        Context initCtx = new InitialContext();
19
                        Context envCtx = (Context) initCtx.lookup("java:comp/env");
20
                        instance = (DataSource) envCtx.lookup("jdbc/Popix");
21
                    } catch (NamingException e) {
22
                        throw new RuntimeException("Error initializing DataSource", e);
23
                    }
24
                }
25
            }
26
        }
27 1 1. getInstance : replaced return value with null for com/popx/persistenza/DataSourceSingleton::getInstance → KILLED
        return instance;
28
    }
29
30
    // Metodo aggiuntivo per impostare un DataSource mock
31
    public static void setInstanceForTest(DataSource mockDataSource) {
32
        instance = mockDataSource;
33
    }
34
}

Mutations

14

1.1
Location : getInstance
Killed by : com.popx.integration.persistenza.RigaOrdineDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.RigaOrdineDAOImplTest]
negated conditional → KILLED

16

1.1
Location : getInstance
Killed by : none
negated conditional → NO_COVERAGE

27

1.1
Location : getInstance
Killed by : com.popx.integration.persistenza.UserDAOImplTest.[engine:junit-jupiter]/[class:com.popx.integration.persistenza.UserDAOImplTest]/[method:getUserByEmail_userDoesNotExist_returnsNull()]
replaced return value with null for com/popx/persistenza/DataSourceSingleton::getInstance → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.2