CoderListener.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2025.
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 it
6
 * every time possible with every body.
7
 *
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 *******************************************************************************/
11
package com.jsql.view.swing.manager.util;
12
13
import com.jsql.util.LogLevelUtil;
14
import com.jsql.util.bruter.ActionCoder;
15
import com.jsql.view.swing.manager.ManagerCoder;
16
import org.apache.commons.lang3.StringUtils;
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
20
import java.awt.event.ActionEvent;
21
import java.awt.event.ActionListener;
22
import java.io.IOException;
23
import java.security.NoSuchAlgorithmException;
24
25
/**
26
 * Action run when this.coderManager.encoding.
27
 */
28
public class CoderListener implements ActionListener {
29
    
30
    /**
31
     * Log4j logger sent to view.
32
     */
33
    private static final Logger LOGGER = LogManager.getRootLogger();
34
    
35
    private final ManagerCoder coderManager;
36
    
37
    public CoderListener(ManagerCoder coderManager) {
38
        this.coderManager = coderManager;
39
    }
40
    
41
    public void actionPerformed() {  // type
42 1 1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE
        this.transform(this.coderManager.getMenuMethod().getText());
43
    }
44
    
45
    public void actionPerformed(String nameMethod) {  // hover
46 1 1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE
        this.transform(nameMethod);
47
    }
48
    
49
    @Override
50
    public void actionPerformed(ActionEvent actionEvent) {  // click
51 1 1. actionPerformed : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        this.coderManager.getMenuMethod().setText(actionEvent.getActionCommand());
52 1 1. actionPerformed : removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE
        this.transform(this.coderManager.getMenuMethod().getText());
53
    }
54
    
55
    private void transform(String labelMethodMenu) {
56
        String nameMethod = labelMethodMenu.replace("Hash to ", StringUtils.EMPTY);
57
        String result;
58
        String textInput = this.coderManager.getTextInput().getText();
59
        
60
        try {
61
            if (
62 1 1. transform : negated conditional → NO_COVERAGE
                StringUtils.isEmpty(textInput)
63 1 1. transform : negated conditional → NO_COVERAGE
                && !ActionCoder.getHashesEmpty().contains(nameMethod)
64
            ) {
65
                throw new IllegalArgumentException("text to convert not found");
66
            } else {
67
                result = ActionCoder.forName(nameMethod).orElseThrow().run(textInput);
68
            }
69
        } catch (
70
            IllegalArgumentException  // also thrown by Base64
71
            | IOException
72
            | NoSuchAlgorithmException e
73
        ) {
74
            result = "Coder failure: " + e.getMessage();
75
            LOGGER.log(LogLevelUtil.IGNORE, e);
76
        }
77
78 1 1. transform : removed call to javax/swing/JTextArea::setText → NO_COVERAGE
        this.coderManager.getResult().setText(result);
79
    }
80
}

Mutations

42

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE

46

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE

51

1.1
Location : actionPerformed
Killed by : none
removed call to javax/swing/JLabel::setText → NO_COVERAGE

52

1.1
Location : actionPerformed
Killed by : none
removed call to com/jsql/view/swing/manager/util/CoderListener::transform → NO_COVERAGE

62

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

63

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

78

1.1
Location : transform
Killed by : none
removed call to javax/swing/JTextArea::setText → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1