Browse Source

Implements testable function signature and first unit test

feature-serializer
fdai5728 3 years ago
committed by fdai6352
parent
commit
b0fca310de
  1. 2
      src/main/java/Credential.java
  2. 10
      src/main/java/CredentialRepository.java
  3. 2
      src/main/java/CredentialRepositoryInterface.java
  4. 14
      src/test/java/CredentialRepositoryTest.java

2
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;

10
src/main/java/CredentialRepository.java

@ -10,7 +10,7 @@ public class CredentialRepository implements CredentialRepositoryInterface{
this.credentials = new ArrayList<Credential>();
}
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();
}
}

2
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();

14
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());
*/
Loading…
Cancel
Save