9 Commits

  1. 9
      src/main/java/Credential.java
  2. 38
      src/main/java/CredentialRepository.java
  3. 4
      src/main/java/CredentialRepositoryInterface.java
  4. 35
      src/test/java/CredentialRepositoryTest.java

9
src/main/java/Credential.java

@ -1,9 +1,5 @@
public class Credential {
/**
* Value Object für das Tupel aus name + pw
*/
private String name, password;
private int id;
@ -27,4 +23,9 @@ public class Credential {
{
this.password = newPassword;
}
public void updateUsername(String newUsername)
{
this.name = newUsername;
}
}

38
src/main/java/CredentialRepository.java

@ -49,7 +49,6 @@ public class CredentialRepository implements CredentialRepositoryInterface{
return null;
}
}
/*
@ -60,20 +59,53 @@ public class CredentialRepository implements CredentialRepositoryInterface{
@Override
public void updatePassword(int index) {
public void updatePassword(int index, String newPassword) {
try{
this.credentials.get(index).upDatePassword(newPassword);
}
catch (IndexOutOfBoundsException outOfBoundsException)
{
System.err.println("No Credential with Index" + index + " found");
}
public void updateUsername(int index){
}
public void updateUsername(int index, String newUsername){
try{
this.credentials.get(index).updateUsername(newUsername);
}
catch (IndexOutOfBoundsException outOfBoundsException)
{
System.err.println("No Credential with Index" + index + " found");
}
}
@Override
public void delete(int index) {
this.credentials.remove(index);
}
/*
this function will be required in the future for catching the left-shift in the arrayList
after one entry was deleted. welp, maybe it won't. can't tell and i've no time atm to
finish this
private int mapIndexToListCounter(int needle) {
for(int c = 0; c<this.credentials.size(); c++)
{
if(this.credentials.get(c).getId() == needle)
{
return c;
}
}
return -1;
}
*/
private int getListSize()
{
return this.credentials.size();

4
src/main/java/CredentialRepositoryInterface.java

@ -3,8 +3,8 @@ public interface CredentialRepositoryInterface {
int createNewCredential(String name, String password);
Credential getCredentialsViaName(String needle);
Credential getCredentialsViaId(int id);
void updatePassword(int index);
void updateUsername(int index);
void updatePassword(int index, String newPassword);
void updateUsername(int indexl, String newUsername);
void delete(int index);
}

35
src/test/java/CredentialRepositoryTest.java

@ -49,13 +49,36 @@ class CredentialRepositoryTest {
}
@Test
void testUpdatePassword(){
this.credentialRepository.createNewCredential("mock", "mock");
this.credentialRepository.updatePassword(0, "newPassword");
Credential c = this.credentialRepository.getCredentialsViaId(0);
Assertions.assertEquals("newPassword", c.getPassword());
}
@Test
void testUpdateUsername(){
this.credentialRepository.createNewCredential("mock", "mock");
this.credentialRepository.updateUsername(0, "newUsername");
Credential c = this.credentialRepository.getCredentialsViaId(0);
Assertions.assertEquals("newUsername", c.getName());
}
@Test
void testDeleteEntry(){
/*
Exception failed = Assertions.assertThrows(Exception.class, () -> {
this.credentialRepository.createNewCredential(null,null);
});
this.credentialRepository.createNewCredential("mock", "mock");
this.credentialRepository.delete(0);
Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaId(0));
}
Assertions.assertEquals("kein leeres Objekt erstellen", failed.getMessage());
*/
}
Loading…
Cancel
Save