|
|
@ -0,0 +1,61 @@ |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Assertions; |
|
|
|
|
|
|
|
class CredentialRepositoryTest { |
|
|
|
|
|
|
|
|
|
|
|
private CredentialRepository credentialRepository; |
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
public void setUp() |
|
|
|
{ |
|
|
|
credentialRepository = new CredentialRepository(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void createNewCredentialAndAddToList() { |
|
|
|
|
|
|
|
Assertions.assertEquals(1, this.credentialRepository.createNewCredential("mock", "mock")); |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void searchForIdInRepository() { |
|
|
|
|
|
|
|
this.credentialRepository.createNewCredential("mock", "mock"); |
|
|
|
this.credentialRepository.createNewCredential("kek", "mate"); |
|
|
|
|
|
|
|
Credential c = this.credentialRepository.getCredentialsViaId(1); |
|
|
|
Assertions.assertEquals("mate", c.getPassword()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testSearchWithInvalidIndex() { |
|
|
|
|
|
|
|
this.credentialRepository.createNewCredential("mock", "mock"); |
|
|
|
|
|
|
|
Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaId(2)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
Exception failed = Assertions.assertThrows(Exception.class, () -> { |
|
|
|
this.credentialRepository.createNewCredential(null,null); |
|
|
|
}); |
|
|
|
|
|
|
|
Assertions.assertEquals("kein leeres Objekt erstellen", failed.getMessage()); |
|
|
|
*/ |