You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
4.2 KiB
119 lines
4.2 KiB
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));
|
|
|
|
}
|
|
|
|
@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(){
|
|
|
|
this.credentialRepository.createNewCredential("mock", "mock");
|
|
this.credentialRepository.delete(0);
|
|
|
|
Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaId(0));
|
|
}
|
|
|
|
@Test
|
|
void testSerializeObject(){
|
|
|
|
this.credentialRepository.createNewCredential("mock", "mock");
|
|
this.credentialRepository.serializeObject("testName");
|
|
}
|
|
|
|
@Test
|
|
void testLoadingOfSerializedObject(){
|
|
|
|
this.credentialRepository.createNewCredential("mock1", "mock1");
|
|
this.credentialRepository.createNewCredential("mock2", "mock2");
|
|
this.credentialRepository.createNewCredential("mock3", "mock3");
|
|
|
|
Credential temporary1 = this.credentialRepository.getCredentialsViaId(0);
|
|
Credential temporary2 = this.credentialRepository.getCredentialsViaId(1);
|
|
Credential temporary3 = this.credentialRepository.getCredentialsViaId(2);
|
|
|
|
this.credentialRepository.serializeObject("unitTest_Deserialization");
|
|
|
|
//delete entries to proove we really load something
|
|
this.credentialRepository.delete(0);
|
|
this.credentialRepository.delete(0);
|
|
Assertions.assertEquals(null, this.credentialRepository.getCredentialsViaName("mock2") );
|
|
|
|
//load and deserialize object and proove objects are back
|
|
this.credentialRepository.deserializeObjects("unitTest_Deserialization");
|
|
Assertions.assertEquals(temporary1.getName(), this.credentialRepository.getCredentialsViaName("mock1").getName());
|
|
Assertions.assertEquals(temporary1.getPassword(), this.credentialRepository.getCredentialsViaName("mock1").getPassword());
|
|
Assertions.assertEquals(temporary2.getName(), this.credentialRepository.getCredentialsViaName("mock2").getName());
|
|
Assertions.assertEquals(temporary2.getPassword(), this.credentialRepository.getCredentialsViaName("mock2").getPassword());
|
|
Assertions.assertEquals(temporary3.getName(), this.credentialRepository.getCredentialsViaName("mock3").getName());
|
|
Assertions.assertEquals(temporary3.getPassword(), this.credentialRepository.getCredentialsViaName("mock3").getPassword());
|
|
}
|
|
|
|
}
|