implement system test
parent
46c2fb84b8
commit
d7b5b91d6d
|
@ -179,3 +179,5 @@ fabric.properties
|
|||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
/.classpath
|
||||
/.project
|
||||
|
|
|
@ -19,10 +19,13 @@ public class EasyMail {
|
|||
passwordConfirmation);
|
||||
}
|
||||
|
||||
public void userSignin(String username, char[] password) throws Exception {
|
||||
public boolean userSignIn(String username, char[] password) throws Exception {
|
||||
this.currentUser = userManager.checkLogin(username, password);
|
||||
if (this.currentUser != null)
|
||||
this.currentUser.getUsermail().signIn();
|
||||
if (this.currentUser == null)
|
||||
return false;
|
||||
|
||||
this.currentUser.getUsermail().signIn();
|
||||
return this.currentUser.getUsermail().getStatus();
|
||||
}
|
||||
|
||||
public boolean removeUser(String username) throws UserNotFoundException {
|
||||
|
@ -53,8 +56,37 @@ public class EasyMail {
|
|||
LocalDateTime timestamp = LocalDateTime.now();
|
||||
Email newEmail = new Email(sender, receiver, subject, content, timestamp);
|
||||
sender.getUsermail().getSentFolder().addEmail(newEmail);
|
||||
receiver.getUsermail().getInbox().addEmail(newEmail);
|
||||
return true;
|
||||
return receiver.getUsermail().getInbox().addEmail(newEmail);
|
||||
}
|
||||
|
||||
public String[] listAllEmailsInInbox() {
|
||||
int size = currentUser.getUsermail().getInbox().getNumberOfEmails();
|
||||
String[] treffer = new String[size];
|
||||
|
||||
for (int i = 0; i < treffer.length; i++)
|
||||
treffer[i] = currentUser.getUsermail().getInbox().toString();
|
||||
|
||||
return treffer;
|
||||
}
|
||||
|
||||
public String[] listAllEmailsInSentFolder() {
|
||||
int size = currentUser.getUsermail().getSentFolder().getNumberOfEmails();
|
||||
String[] treffer = new String[size];
|
||||
|
||||
for (int i = 0; i < treffer.length; i++)
|
||||
treffer[i] = currentUser.getUsermail().getSentFolder().toString();
|
||||
|
||||
return treffer;
|
||||
}
|
||||
|
||||
public String[] listAllEmailsInTrashFolder() {
|
||||
int size = currentUser.getUsermail().getTrashFolder().getNumberOfEmails();
|
||||
String[] treffer = new String[size];
|
||||
|
||||
for (int i = 0; i < treffer.length; i++)
|
||||
treffer[i] = currentUser.getUsermail().getTrashFolder().toString();
|
||||
|
||||
return treffer;
|
||||
}
|
||||
|
||||
public boolean removeEmailFromInbox(String subject) throws Exception {
|
||||
|
@ -76,7 +108,7 @@ public class EasyMail {
|
|||
if (!this.currentUser.getUsermail().getStatus())
|
||||
throw new IllegalStateException("No user is currently logged in!");
|
||||
|
||||
Email removedEmail= this.currentUser.getUsermail().getInbox().removeEmail(subject);
|
||||
Email removedEmail = this.currentUser.getUsermail().getInbox().removeEmail(subject);
|
||||
return this.currentUser.getUsermail().getTrashFolder().addEmail(removedEmail);
|
||||
}
|
||||
|
||||
|
@ -90,7 +122,6 @@ public class EasyMail {
|
|||
this.currentUser.getUsermail().getTrashFolder().removeEmail(subject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
class EasyMailTest {
|
||||
|
||||
private EasyMail easyMail;
|
||||
private char[] password;
|
||||
private char[] confirmPassword;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
easyMail = new EasyMail();
|
||||
password = "password123".toCharArray();
|
||||
confirmPassword = "password123".toCharArray();
|
||||
|
||||
// User registrieren
|
||||
easyMail.userRegister("Alice", "Wonder", "alice", 1995, 20, "Juli", password, confirmPassword);
|
||||
easyMail.userRegister("Bob", "Marley", "bob", 1990, 1, "Juni", password, confirmPassword);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUserSignin() throws Exception {
|
||||
boolean userSignIn = easyMail.userSignIn("alice@easymail.de", "password123".toCharArray());
|
||||
assertTrue(userSignIn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendEmail() throws Exception {
|
||||
easyMail.userSignIn("alice@easymail.de", "password123".toCharArray());
|
||||
boolean result = easyMail.sendEmail("bob@easymail.de", "Hello", "This is a test email.");
|
||||
|
||||
assertTrue(result);
|
||||
String[] sentEmails = easyMail.listAllEmailsInSentFolder();
|
||||
assertEquals(1, sentEmails.length);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package domain.email;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface EmailFolder {
|
||||
|
||||
boolean addEmail(Email email);
|
||||
|
@ -7,5 +9,5 @@ public interface EmailFolder {
|
|||
Email getEmailBySubject(String subject) throws EmailNotFoundException ;
|
||||
int getNumberOfEmails();
|
||||
boolean clearAllEmails();
|
||||
String[] listAllEmails();
|
||||
ArrayList<Email>listAllEmails();
|
||||
}
|
||||
|
|
|
@ -57,12 +57,9 @@ public class Inbox implements EmailFolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String[] listAllEmails() {
|
||||
String[] subjects = new String[receivedEmails.size()];
|
||||
for (int i = 0; i < receivedEmails.size(); i++) {
|
||||
subjects[i] = receivedEmails.get(i).getSubject();
|
||||
}
|
||||
return subjects;
|
||||
public ArrayList<Email> listAllEmails() {
|
||||
return new ArrayList<>(receivedEmails); // sichere Kopie
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -53,11 +53,8 @@ public class SentFolder implements EmailFolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String[] listAllEmails() {
|
||||
String[] subjects = new String[emails.size()];
|
||||
for (int i = 0; i < emails.size(); i++)
|
||||
subjects[i] = emails.get(i).toString();
|
||||
|
||||
return subjects;
|
||||
public ArrayList<Email> listAllEmails() {
|
||||
return new ArrayList<>(emails);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,12 +56,8 @@ public class TrashFolder implements EmailFolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String[] listAllEmails() {
|
||||
String[] subjects = new String[removedEmails.size()];
|
||||
for (int i = 0; i < removedEmails.size(); i++)
|
||||
subjects[i] = removedEmails.get(i).toString();
|
||||
|
||||
return subjects;
|
||||
public ArrayList<Email> listAllEmails() {
|
||||
return new ArrayList<>(removedEmails);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue