Database.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
3
 * This program and the accompanying materials
4
 * are made available under no term at all, use it like
5
 * you want, but share and discuss about it
6
 * every time possible with every body.
7
 * 
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 ******************************************************************************/
11
package com.jsql.model.bean.database;
12
13
import com.jsql.util.LogLevelUtil;
14
import org.apache.commons.lang3.StringUtils;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
18
/**
19
 * Define a Database, e.g. is sent to the view by the model after injection.
20
 */
21
public class Database extends AbstractElementDatabase {
22
    
23
    /**
24
     * Log4j logger sent to view.
25
     */
26
    private static final Logger LOGGER = LogManager.getRootLogger();
27
    
28
    // The number of tables in the database.
29
    // TODO to int
30
    private String tableCount;
31
32
    /**
33
     * Define the database label and number of tables.
34
     * @param databaseName
35
     * @param tableCount
36
     */
37
    public Database(String databaseName, String tableCount) {
38
        
39
        this.elementValue = databaseName;
40
        this.tableCount = tableCount;
41
    }
42
43
    // A database has no parent.
44
    @Override
45
    public AbstractElementDatabase getParent() {
46
        return null;
47
    }
48
    
49
    // Return the number of tables in the table.
50
    @Override
51
    public int getChildCount() {
52 1 1. getChildCount : replaced int return with 0 for com/jsql/model/bean/database/Database::getChildCount → NO_COVERAGE
        return Integer.parseInt(this.tableCount);
53
    }
54
55
    /**
56
     * A readable label for the database, with number of tables,
57
     * displayed by the view, e.g. my_database (7 tables).
58
     */
59
    @Override
60
    public String getLabelCount() {
61
        
62
        // Report #1500: detect incorrect number of tables
63
        String sPlural = StringUtils.EMPTY;
64
        
65
        try {
66 2 1. getLabelCount : changed conditional boundary → SURVIVED
2. getLabelCount : negated conditional → KILLED
            if (Integer.parseInt(this.tableCount) > 1) {
67
                sPlural = "s";
68
            }
69
        } catch (NumberFormatException e) {
70
            
71
            this.tableCount = "0";
72
            LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Incorrect number of tables for [{}].", this);
73
        }
74
        
75 1 1. getLabelCount : replaced return value with "" for com/jsql/model/bean/database/Database::getLabelCount → KILLED
        return String.format(
76
            "%s (%s table%s)",
77
            this.elementValue,
78
            this.tableCount,
79
            sPlural
80
        );
81
    }
82
}

Mutations

52

1.1
Location : getChildCount
Killed by : none
replaced int return with 0 for com/jsql/model/bean/database/Database::getChildCount → NO_COVERAGE

66

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

2.2
Location : getLabelCount
Killed by : BeanDatabaseSpock.[engine:spock]/[spec:BeanDatabaseSpock]/[feature:$spock_feature_0_3]/[iteration:0]
negated conditional → KILLED

75

1.1
Location : getLabelCount
Killed by : BeanDatabaseSpock.[engine:spock]/[spec:BeanDatabaseSpock]/[feature:$spock_feature_0_3]/[iteration:0]
replaced return value with "" for com/jsql/model/bean/database/Database::getLabelCount → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1