From 353de7a02573d793dfcaafd34cecf0d8b32c1be2 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 16:45:24 +0100 Subject: [PATCH 01/21] Implements an Interface with basic functions Defines New Credential function signature --- src/main/java/CredentialInterface.java | 11 ----------- src/main/java/CredentialRepositoryInterface.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 src/main/java/CredentialInterface.java create mode 100644 src/main/java/CredentialRepositoryInterface.java diff --git a/src/main/java/CredentialInterface.java b/src/main/java/CredentialInterface.java deleted file mode 100644 index f6e0ead..0000000 --- a/src/main/java/CredentialInterface.java +++ /dev/null @@ -1,11 +0,0 @@ -public interface CredentialInterface { - - public void show(); - public void edit(); - public void delete(); - public void getCredentials(); - public void setCredentials(); - public void getAsJSON(); - public void loadCredentialsFromJSON(); - -} diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java new file mode 100644 index 0000000..055b59e --- /dev/null +++ b/src/main/java/CredentialRepositoryInterface.java @@ -0,0 +1,11 @@ +public interface CredentialRepositoryInterface { + + void createNewCredential(String name, String password); + void edit(); + void delete(); + void getCredentials(); + void setCredentials(); + void getAsJSON(); + void loadCredentialsFromJSON(); + +} From e3013269d2470e3c02d1d5a7b003b1fefe01af15 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 16:47:55 +0100 Subject: [PATCH 02/21] Implements Skeleton for CredentialRepository Defines Constructor - Credentials are Held in ArrayList for ease of use Defines public function to add new credential with incrementing indizes --- src/main/java/CredentialRepository.java | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/java/CredentialRepository.java diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java new file mode 100644 index 0000000..3964dd6 --- /dev/null +++ b/src/main/java/CredentialRepository.java @@ -0,0 +1,55 @@ +import java.util.ArrayList; + +public class CredentialRepository implements CredentialRepositoryInterface{ + + private int idCounter = 0; + private ArrayList credentials; + + public CredentialRepository() + { + this.credentials = new ArrayList(); + } + + public void createNewCredential(String name, String password) + { + try { + this.credentials.add(new Credential(name, password, this.idCounter++)); + } + catch(Exception fail) + { + System.err.println(fail.getMessage()); + } + } + + @Override + public void edit() { + + } + + @Override + public void delete() { + + } + + @Override + public void getCredentials() { + + } + + @Override + public void setCredentials() { + + } + + @Override + public void getAsJSON() { + + } + + @Override + public void loadCredentialsFromJSON() { + + } +} + + From 40bbfbb19625bdd7e561cd996f48cca6c0cf9fe6 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 16:48:46 +0100 Subject: [PATCH 03/21] Implements a Value Object to hold user information --- src/main/java/Credential.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/Credential.java diff --git a/src/main/java/Credential.java b/src/main/java/Credential.java new file mode 100644 index 0000000..702a60b --- /dev/null +++ b/src/main/java/Credential.java @@ -0,0 +1,30 @@ +public class Credential { + + /** + * Value Object für das Tupel aus name + pw + */ + + private String name, password; + private int id; + + + public Credential(String name, String password, int id) throws Exception { + if(name == null || password == null) + throw new Exception("kein leeres Objekt erstellen bliat"); + + this.name = name; + this.password = password; + } + + public String getName() + { + return this.name; + } + public String getPassword() { return this.password; } + public int getId() { return this.id; } + + public void upDatePassword(String newPassword) + { + this.password = newPassword; + } +} From 1c22b4912c65b18bbbb47283d33d7419facaa401 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 16:52:32 +0100 Subject: [PATCH 04/21] Creates Testclass for CredentialRepository Adds basic layout and @beforeAll setup function --- src/test/java/CredentialRepositoryTest.java | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/java/CredentialRepositoryTest.java diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java new file mode 100644 index 0000000..bf29066 --- /dev/null +++ b/src/test/java/CredentialRepositoryTest.java @@ -0,0 +1,22 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class CredentialRepositoryTest { + + + private CredentialRepository credentialRepository; + + @BeforeEach + public void setUp() + { + credentialRepository = new CredentialRepository(); + } + + @Test + void createNewCredentialAndAddToList() { + + + + } + +} From 950cbae5a4f2fbc0c84d1b79b78a3b63621044a5 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:09:09 +0100 Subject: [PATCH 05/21] Implements testable function signature and first unit test --- src/main/java/Credential.java | 2 +- src/main/java/CredentialRepository.java | 10 +++++++++- src/main/java/CredentialRepositoryInterface.java | 2 +- src/test/java/CredentialRepositoryTest.java | 14 ++++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/java/Credential.java b/src/main/java/Credential.java index 702a60b..b7b4fbd 100644 --- a/src/main/java/Credential.java +++ b/src/main/java/Credential.java @@ -10,7 +10,7 @@ public class Credential { public Credential(String name, String password, int id) throws Exception { if(name == null || password == null) - throw new Exception("kein leeres Objekt erstellen bliat"); + throw new Exception("kein leeres Objekt erstellen"); this.name = name; this.password = password; diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 3964dd6..1a5a6b5 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -10,7 +10,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{ this.credentials = new ArrayList(); } - public void createNewCredential(String name, String password) + public int createNewCredential(String name, String password) { try { this.credentials.add(new Credential(name, password, this.idCounter++)); @@ -19,6 +19,8 @@ public class CredentialRepository implements CredentialRepositoryInterface{ { System.err.println(fail.getMessage()); } + + return this.getListSize(); } @Override @@ -50,6 +52,12 @@ public class CredentialRepository implements CredentialRepositoryInterface{ public void loadCredentialsFromJSON() { } + + private int getListSize() + { + return this.credentials.size(); + } + } diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index 055b59e..7730f2d 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -1,6 +1,6 @@ public interface CredentialRepositoryInterface { - void createNewCredential(String name, String password); + int createNewCredential(String name, String password); void edit(); void delete(); void getCredentials(); diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index bf29066..d3a6f67 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -1,5 +1,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; class CredentialRepositoryTest { @@ -15,8 +16,17 @@ class CredentialRepositoryTest { @Test void createNewCredentialAndAddToList() { - - + Assertions.assertEquals(1, this.credentialRepository.createNewCredential("mock", "mock")); + Assertions.assertEquals(2, this.credentialRepository.createNewCredential("kek", "mate")); } } + + + /* + Exception failed = Assertions.assertThrows(Exception.class, () -> { + this.credentialRepository.createNewCredential(null,null); + }); + + Assertions.assertEquals("kein leeres Objekt erstellen", failed.getMessage()); + */ \ No newline at end of file From 60626bc4f3dbc4086d7156db000f227b27785443 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:16:40 +0100 Subject: [PATCH 06/21] Implements test for search function over repository --- src/main/java/CredentialRepository.java | 13 ++++++++++++- src/main/java/CredentialRepositoryInterface.java | 3 ++- src/test/java/CredentialRepositoryTest.java | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 1a5a6b5..f8f66f3 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -33,8 +33,19 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + public Credential getCredentialsViaName(String needle) { + + for(int c = 0; c < this.getListSize(); c++) + { + + } + + return null; + } + + @Override - public void getCredentials() { + public void getCredentialsViaId() { } diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index 7730f2d..de543eb 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -3,7 +3,8 @@ public interface CredentialRepositoryInterface { int createNewCredential(String name, String password); void edit(); void delete(); - void getCredentials(); + void getCredentialsViaName(); + void getCredentialsViaId(); void setCredentials(); void getAsJSON(); void loadCredentialsFromJSON(); diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index d3a6f67..36fe139 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -20,6 +20,17 @@ class CredentialRepositoryTest { Assertions.assertEquals(2, this.credentialRepository.createNewCredential("kek", "mate")); } + @Test + void searchForUserInRepository() { + + this.credentialRepository.createNewCredential("mock", "mock"); + this.credentialRepository.createNewCredential("kek", "mate"); + + Credential c = this.credentialRepository.getCredentialsViaName("kek"); + Assertions.assertEquals("mate", c.getPassword()); + } + + } From fbb7efedcf0f443f4731f313ac55ce21894195d8 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:21:41 +0100 Subject: [PATCH 07/21] Implements search function and test for search --- src/main/java/CredentialRepository.java | 7 ++++++- src/main/java/CredentialRepositoryInterface.java | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index f8f66f3..2c49131 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -33,11 +33,15 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + @Override public Credential getCredentialsViaName(String needle) { for(int c = 0; c < this.getListSize(); c++) { + Credential credential = this.credentials.get(c); + if(credential.getName().equals(needle)) + return credential; } return null; @@ -45,8 +49,9 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override - public void getCredentialsViaId() { + public Credential getCredentialsViaId() { + return null; } @Override diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index de543eb..85db2ed 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -3,8 +3,8 @@ public interface CredentialRepositoryInterface { int createNewCredential(String name, String password); void edit(); void delete(); - void getCredentialsViaName(); - void getCredentialsViaId(); + Credential getCredentialsViaName(String needle); + Credential getCredentialsViaId(); void setCredentials(); void getAsJSON(); void loadCredentialsFromJSON(); From 78db2e5908fbb5347eb13ab1f2051c8c80f1fbc9 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:29:22 +0100 Subject: [PATCH 08/21] Implements search function and test for search via index --- src/main/java/CredentialRepository.java | 14 +++++++++++--- .../java/CredentialRepositoryInterface.java | 2 +- src/test/java/CredentialRepositoryTest.java | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 2c49131..acc0c08 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -2,7 +2,7 @@ import java.util.ArrayList; public class CredentialRepository implements CredentialRepositoryInterface{ - private int idCounter = 0; + private int idCounter = 1; private ArrayList credentials; public CredentialRepository() @@ -49,9 +49,17 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override - public Credential getCredentialsViaId() { + public Credential getCredentialsViaId(int id) { + + try{ + return this.credentials.get(id); + } + catch (IndexOutOfBoundsException outOfBoundsException) + { + return null; + } + - return null; } @Override diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index 85db2ed..19750c6 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -4,7 +4,7 @@ public interface CredentialRepositoryInterface { void edit(); void delete(); Credential getCredentialsViaName(String needle); - Credential getCredentialsViaId(); + Credential getCredentialsViaId(int id); void setCredentials(); void getAsJSON(); void loadCredentialsFromJSON(); diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index 36fe139..bb10bc6 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -30,6 +30,24 @@ class CredentialRepositoryTest { Assertions.assertEquals("mate", c.getPassword()); } + @Test + void searchForIdInRepository() { + + this.credentialRepository.createNewCredential("mock", "mock"); + this.credentialRepository.createNewCredential("kek", "mate"); + + Credential c = this.credentialRepository.getCredentialsViaId(2); + Assertions.assertEquals("mate", c.getPassword()); + } + + @Test + void testSearchWithInvalidIndex() { + + this.credentialRepository.createNewCredential("mock", "mock"); + + Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaId(2)); + + } } From bfd8af9c56f95c6061f01f60af1be0bb33f4bb14 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:34:15 +0100 Subject: [PATCH 09/21] Fix counter error in arrayList --- src/main/java/CredentialRepository.java | 2 +- src/test/java/CredentialRepositoryTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index acc0c08..4dd28dd 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -2,7 +2,7 @@ import java.util.ArrayList; public class CredentialRepository implements CredentialRepositoryInterface{ - private int idCounter = 1; + private int idCounter = 0; private ArrayList credentials; public CredentialRepository() diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index bb10bc6..9159b87 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -36,7 +36,7 @@ class CredentialRepositoryTest { this.credentialRepository.createNewCredential("mock", "mock"); this.credentialRepository.createNewCredential("kek", "mate"); - Credential c = this.credentialRepository.getCredentialsViaId(2); + Credential c = this.credentialRepository.getCredentialsViaId(1); Assertions.assertEquals("mate", c.getPassword()); } From 23647550bc58ad5e0007a684d810aa8581dd83c5 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:36:15 +0100 Subject: [PATCH 10/21] Removes unused functions --- src/main/java/CredentialRepository.java | 15 --------------- src/main/java/CredentialRepositoryInterface.java | 3 --- 2 files changed, 18 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 4dd28dd..9863c6f 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -60,21 +60,6 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } - } - - @Override - public void setCredentials() { - - } - - @Override - public void getAsJSON() { - - } - - @Override - public void loadCredentialsFromJSON() { - } private int getListSize() diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index 19750c6..ff04aac 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -5,8 +5,5 @@ public interface CredentialRepositoryInterface { void delete(); Credential getCredentialsViaName(String needle); Credential getCredentialsViaId(int id); - void setCredentials(); - void getAsJSON(); - void loadCredentialsFromJSON(); } From 957f652258b3fec2fafd7c31fde2ab6507e85d94 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:39:11 +0100 Subject: [PATCH 11/21] Restructures repository class and interface --- src/main/java/CredentialRepository.java | 32 +++++++++++++------ .../java/CredentialRepositoryInterface.java | 5 +-- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 9863c6f..3fe9f97 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -23,16 +23,6 @@ public class CredentialRepository implements CredentialRepositoryInterface{ return this.getListSize(); } - @Override - public void edit() { - - } - - @Override - public void delete() { - - } - @Override public Credential getCredentialsViaName(String needle) { @@ -62,6 +52,28 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } + /* + The next 3 functions assume you already have successfully + pulled a credential from the repository and now want to edit it. + Thus, these functions require you to pass the desired credential's index + */ + + + @Override + public void updatePassword(int index) { + + } + + public void updateUsername(int index){ + + } + + @Override + public void delete(int index) { + + } + + private int getListSize() { return this.credentials.size(); diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index ff04aac..da4696c 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/src/main/java/CredentialRepositoryInterface.java @@ -1,9 +1,10 @@ public interface CredentialRepositoryInterface { int createNewCredential(String name, String password); - void edit(); - void delete(); Credential getCredentialsViaName(String needle); Credential getCredentialsViaId(int id); + void updatePassword(int index); + void updateUsername(int index); + void delete(int index); } From 0bfd2875fefacb42c777689452f0bf1cd0e1a64b Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:47:37 +0100 Subject: [PATCH 12/21] Rewrite ValueObject to DTO since we don't want to destroy the old object each time it gets updated --- src/main/java/Credential.java | 9 +++++---- src/main/java/CredentialRepository.java | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/Credential.java b/src/main/java/Credential.java index b7b4fbd..506fdb7 100644 --- a/src/main/java/Credential.java +++ b/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; + } } diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 3fe9f97..7b5dab2 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -62,6 +62,8 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override public void updatePassword(int index) { + + } public void updateUsername(int index){ From a048e3572c9ff2c49d90c962fe10cf6b786e6439 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:49:48 +0100 Subject: [PATCH 13/21] Updates Interface and function signatures --- src/main/java/CredentialRepository.java | 10 ++++++++-- src/main/java/CredentialRepositoryInterface.java | 4 ++-- src/test/java/CredentialRepositoryTest.java | 13 ++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 7b5dab2..a1837f2 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -60,13 +60,19 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override - public void updatePassword(int index) { + public void updatePassword(int index, String newPassword) { + try{ + + } + catch (IndexOutOfBoundsException outOfBoundsException) + { + } } - public void updateUsername(int index){ + public void updateUsername(int index, String newUsername){ } diff --git a/src/main/java/CredentialRepositoryInterface.java b/src/main/java/CredentialRepositoryInterface.java index da4696c..afff4b0 100644 --- a/src/main/java/CredentialRepositoryInterface.java +++ b/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); } diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index 9159b87..7ce26d3 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -49,13 +49,12 @@ class CredentialRepositoryTest { } -} + @Test + void testUpdatePassword(){ + // this.credentialRepository.createNewCredential("mock", "mock"); + // this.credentialRepository.updatePassword(0); - /* - Exception failed = Assertions.assertThrows(Exception.class, () -> { - this.credentialRepository.createNewCredential(null,null); - }); + } - Assertions.assertEquals("kein leeres Objekt erstellen", failed.getMessage()); - */ \ No newline at end of file +} From 8190c10f3c28f17bb0be2d8661d99afb268b5732 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:51:19 +0100 Subject: [PATCH 14/21] Implements Unittest for Password Update --- src/test/java/CredentialRepositoryTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index 7ce26d3..c7298fb 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -52,8 +52,12 @@ class CredentialRepositoryTest { @Test void testUpdatePassword(){ - // this.credentialRepository.createNewCredential("mock", "mock"); - // this.credentialRepository.updatePassword(0); + this.credentialRepository.createNewCredential("mock", "mock"); + this.credentialRepository.updatePassword(0, "newPassword"); + + Credential c = this.credentialRepository.getCredentialsViaId(0); + + Assertions.assertEquals("newPassword", c.getPassword()); } From 4a6c72ec8f93490f20f1c718e17566cbd81197bf Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:52:04 +0100 Subject: [PATCH 15/21] Implements function for Password Update --- src/main/java/CredentialRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index a1837f2..58122d5 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -63,7 +63,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{ public void updatePassword(int index, String newPassword) { try{ - + this.credentials.get(index).upDatePassword(newPassword); } catch (IndexOutOfBoundsException outOfBoundsException) { From 04eb3200bf95c5bbfb079e3cd448f0cc9834f21d Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:52:52 +0100 Subject: [PATCH 16/21] Implements Unittest for Username Update --- src/test/java/CredentialRepositoryTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index c7298fb..dcd87a5 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -61,4 +61,16 @@ class CredentialRepositoryTest { } + @Test + void testUpdateUsername(){ + + this.credentialRepository.createNewCredential("mock", "mock"); + this.credentialRepository.updateUsername(0, "newUsername"); + + Credential c = this.credentialRepository.getCredentialsViaId(0); + + Assertions.assertEquals("newPassword", c.getName()); + + } + } From cbb280326ff28e8b754ffb2f910e32ed054c6749 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:53:56 +0100 Subject: [PATCH 17/21] Implements function for Username Update --- src/main/java/CredentialRepository.java | 7 +++++++ src/test/java/CredentialRepositoryTest.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 58122d5..1a331c7 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -74,6 +74,13 @@ public class CredentialRepository implements CredentialRepositoryInterface{ public void updateUsername(int index, String newUsername){ + try{ + this.credentials.get(index).updateUsername(newUsername); + } + catch (IndexOutOfBoundsException outOfBoundsException) + { + + } } @Override diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index dcd87a5..b7b0674 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -69,7 +69,7 @@ class CredentialRepositoryTest { Credential c = this.credentialRepository.getCredentialsViaId(0); - Assertions.assertEquals("newPassword", c.getName()); + Assertions.assertEquals("newUsername", c.getName()); } From d616b6f9cb64e1b5505672f9c3c5591b836cc0be Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 17:54:51 +0100 Subject: [PATCH 18/21] Adds error printing for indexoutofbound case --- src/main/java/CredentialRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 1a331c7..c47d507 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -67,7 +67,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } catch (IndexOutOfBoundsException outOfBoundsException) { - + System.err.println("No Credential with Index" + index + " found"); } } @@ -79,7 +79,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } catch (IndexOutOfBoundsException outOfBoundsException) { - + System.err.println("No Credential with Index" + index + " found"); } } From c5254acda69a78066665e82fd58f8a22573e0e3a Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 18:02:06 +0100 Subject: [PATCH 19/21] Implements Unittest and function to delete credential from arraylist --- src/main/java/CredentialRepository.java | 2 ++ src/test/java/CredentialRepositoryTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index c47d507..8e1adc9 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -86,6 +86,8 @@ public class CredentialRepository implements CredentialRepositoryInterface{ @Override public void delete(int index) { + this.credentials.remove(index); + } diff --git a/src/test/java/CredentialRepositoryTest.java b/src/test/java/CredentialRepositoryTest.java index b7b0674..3806d09 100644 --- a/src/test/java/CredentialRepositoryTest.java +++ b/src/test/java/CredentialRepositoryTest.java @@ -70,6 +70,19 @@ class CredentialRepositoryTest { Credential c = this.credentialRepository.getCredentialsViaId(0); Assertions.assertEquals("newUsername", c.getName()); + } + + @Test + void testDeleteEntry(){ + + this.credentialRepository.createNewCredential("mock", "mock"); + this.credentialRepository.delete(0); + + Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaId(0)); + } + + @Test + void testIndexShiftAfterDeletion(){ } From 75ffb1854a3ccdc9545822cff73a568754be7854 Mon Sep 17 00:00:00 2001 From: fdai5728 Date: Wed, 16 Feb 2022 18:20:47 +0100 Subject: [PATCH 20/21] Reverts some mistakes Implements and tests function to delete entries @TODO: catch index left-shift after deleting an item --- src/main/java/CredentialRepository.java | 17 ++++++++++++++++- src/test/java/CredentialRepositoryTest.java | 5 ----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/CredentialRepository.java b/src/main/java/CredentialRepository.java index 8e1adc9..6a048cc 100644 --- a/src/main/java/CredentialRepository.java +++ b/src/main/java/CredentialRepository.java @@ -49,7 +49,6 @@ public class CredentialRepository implements CredentialRepositoryInterface{ return null; } - } /* @@ -90,7 +89,23 @@ public class CredentialRepository implements CredentialRepositoryInterface{ } +/* + 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 Date: Wed, 16 Feb 2022 18:47:04 +0100 Subject: [PATCH 21/21] =?UTF-8?q?erneuter=20commit,=20l=C3=B6scht=20hoffen?= =?UTF-8?q?tlich=20datei,=20versuch=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Credentials.java | 38 ---------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 src/main/java/Credentials.java diff --git a/src/main/java/Credentials.java b/src/main/java/Credentials.java deleted file mode 100644 index 028f58b..0000000 --- a/src/main/java/Credentials.java +++ /dev/null @@ -1,38 +0,0 @@ -public class Credentials implements CredentialInterface{ - @Override - public void show() { - - } - - @Override - public void edit() { - - } - - @Override - public void delete() { - - } - - @Override - public void getCredentials() { - - } - - @Override - public void setCredentials() { - - } - - @Override - public void getAsJSON() { - - } - - @Override - public void loadCredentialsFromJSON() { - - } -} - -