Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testSaveAccountShowErrorLabelIfAccountAlreadyExists() {
window.textBox("textFieldPassword").enterText(accountToSave.getCredential().getPassword());
window.button("buttonSaveAccount").click();
assertThat(window.label("labelErrorMessage").text())
.isEqualTo("Already existing credential for the same site with the same username: " + accountToSave);
.isEqualTo("Already existing: " + accountToSave);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void testSaveAccountAlreadyPresentDipslayErrorLabel() {
window.textBox("textFieldPassword").enterText(accountToSave.getCredential().getPassword());
window.button("buttonSaveAccount").click();
assertThat(window.label("labelErrorMessage").text())
.isEqualTo("Already existing credential for the same site with the same username: "+accountToSave.toString());
.isEqualTo("Already existing: "+accountToSave.toString());
assertThat(accountRedisRepository.findAll()).containsExactly(accountToSave);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void findAccountsByPassword(String password) {

public void saveAccount(Account accountToSave) {
if(checkIfAccountAlreadyExists(accountToSave)) {
accountView.showError("Already existing credential for the same site with the same username", accountToSave);
accountView.showError("Already existing: ", accountToSave);
}else {
accountRepository.save(accountToSave);
accountView.accountIsAdded();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.justgiulio.passwordmanager.view.swing;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
Expand Down Expand Up @@ -67,6 +68,7 @@ private void initComponents() {
labelErrorMessage = new javax.swing.JLabel();
labelErrorMessage.setEnabled(false);
labelErrorMessage.setName("labelErrorMessage");
labelErrorMessage.setSize(new Dimension(100,200));
jSeparator2 = new javax.swing.JSeparator();
jPanel4 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
Expand Down Expand Up @@ -192,13 +194,13 @@ private void initComponents() {
jLabel7.setText("Length");

sliderPasswordLength.setMaximum(32);
sliderPasswordLength.setMinimum(1);
sliderPasswordLength.setMinimum(8);
sliderPasswordLength.setMinorTickSpacing(1);
sliderPasswordLength.setPaintLabels(true);
sliderPasswordLength.setPaintTicks(true);
sliderPasswordLength.setSnapToTicks(true);
sliderPasswordLength.setToolTipText("");
sliderPasswordLength.setValue(1);
sliderPasswordLength.setValue(8);

buttonGeneratePassword.setFont(new java.awt.Font(SELECTED_FONT, 1, 16)); // NOI18N
buttonGeneratePassword.setText("Generate");
Expand Down Expand Up @@ -283,12 +285,12 @@ private void initComponents() {
buttonDeleteAccount.setName("buttonDeleteAccount");
buttonDeleteAccount.setEnabled(false);

JButton buttonModifyUsername = new JButton("Modify Username");
buttonModifyUsername = new JButton("Modify Username");
buttonModifyUsername.setActionCommand(ACTION_MODIFY_USERNAME);
buttonModifyUsername.setName("buttonModifyUsername");
buttonModifyUsername.setEnabled(false);

JButton buttonModifyPassword = new JButton("Modify Password");
buttonModifyPassword = new JButton("Modify Password");
buttonModifyPassword.setActionCommand("MODIFY_PASSWORD");
buttonModifyPassword.setName("buttonModifyPassword");
buttonModifyPassword.setEnabled(false);
Expand Down Expand Up @@ -435,8 +437,9 @@ public void keyReleased(KeyEvent e) {
radioButtonGroupPasswordStrength.add(radioButtonHighStrength);

sliderLengthPasswordLabel = new Hashtable<>();
sliderLengthPasswordLabel.put(1, new JLabel("1"));
sliderLengthPasswordLabel.put(16, new JLabel("15"));
sliderLengthPasswordLabel.put(8, new JLabel("8"));
sliderLengthPasswordLabel.put(16, new JLabel("16"));
sliderLengthPasswordLabel.put(24, new JLabel("24"));
sliderLengthPasswordLabel.put(32, new JLabel("32"));
sliderPasswordLength.setLabelTable(sliderLengthPasswordLabel);
sliderPasswordLength.setPaintLabels(true);
Expand Down Expand Up @@ -623,6 +626,8 @@ public void actionPerformed(ActionEvent actionEvent) {
private JLabel labelOperationResult;
private JLabel labelAccountAdded;
private static final String SELECTED_FONT = "sansserif";
private javax.swing.JButton buttonModifyUsername;
private javax.swing.JButton buttonModifyPassword;

public void setListAccountTableData(List<Account> accountsTableData) {
SwingUtilities.invokeLater(() -> {
Expand All @@ -643,10 +648,9 @@ public void accountIsAdded() {
SwingUtilities.invokeLater(() -> {
labelAccountAdded.setEnabled(true);
labelAccountAdded.setText("Account Saved!");
textFieldUsername.setText("");
textFieldSiteName.setText("");
textFieldPassword.setText("");

resetTextFieldAccounts();
resetErrorLabel();
buttonSaveAccount.setEnabled(false);
});
}

Expand All @@ -655,14 +659,16 @@ public void showError(String string) {
SwingUtilities.invokeLater(() -> {
labelErrorMessage.setEnabled(true);
labelErrorMessage.setText(string);
resetAccountAddedLabel();
});
}

@Override
public void showError(String string, Account accountToSave) {
SwingUtilities.invokeLater(() -> {
labelErrorMessage.setEnabled(true);
labelErrorMessage.setText(string + ": " + accountToSave);
labelErrorMessage.setText(string + accountToSave);
resetAccountAddedLabel();
});
}

Expand All @@ -672,6 +678,7 @@ public void accountIsModified() {
labelOperationResult.setEnabled(true);
labelOperationResult.setText("Account Modified!");
textFieldUpdateCell.setText("");
resetModifyButtonsState();
});

}
Expand Down Expand Up @@ -709,6 +716,13 @@ private void resetLabelOperationResult() {
labelOperationResult.setText("");
});
}

private void resetModifyButtonsState() {
SwingUtilities.invokeLater(() -> {
buttonModifyPassword.setEnabled(false);
buttonModifyUsername.setEnabled(false);
});
}

private void resetErrorLabel() {
SwingUtilities.invokeLater(() -> {
Expand All @@ -723,6 +737,15 @@ private void resetAccountAddedLabel() {
labelAccountAdded.setText("");
});
}

private void resetTextFieldAccounts() {
SwingUtilities.invokeLater(() -> {
textFieldUsername.setText("");
textFieldSiteName.setText("");
textFieldPassword.setText("");
});

}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ public String getColumnName(int col) {
return columnNames[col];
}

/**
* Cell are editable to allow user to copy the username or password
* it is not intended to modify the field, to achieve this goal use buttons instead
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
boolean result = true;
if(columnIndex == 0) result = false;
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void saveAccountAlreadyExistsTest() {
Account accountAlreadySaved = new Account("github.com", new Credential("giulio","passgiulio"));
when(accountRepository.findByKey(site)).thenReturn(Arrays.asList(accountToSave, new Account("github.com",new Credential("remeic","passremeic"))));
controller.saveAccount(accountToSave);
verify(accountView).showError("Already existing credential for the same site with the same username", accountAlreadySaved);
verify(accountView).showError("Already existing: ", accountAlreadySaved);
verifyNoMoreInteractions(ignoreStubs(accountRepository));
}

Expand Down
Loading