implement system test
parent
46c2fb84b8
commit
d7b5b91d6d
|
@ -179,3 +179,5 @@ fabric.properties
|
||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
/.classpath
|
||||||
|
/.project
|
||||||
|
|
|
@ -19,10 +19,13 @@ public class EasyMail {
|
||||||
passwordConfirmation);
|
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);
|
this.currentUser = userManager.checkLogin(username, password);
|
||||||
if (this.currentUser != null)
|
if (this.currentUser == null)
|
||||||
this.currentUser.getUsermail().signIn();
|
return false;
|
||||||
|
|
||||||
|
this.currentUser.getUsermail().signIn();
|
||||||
|
return this.currentUser.getUsermail().getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeUser(String username) throws UserNotFoundException {
|
public boolean removeUser(String username) throws UserNotFoundException {
|
||||||
|
@ -53,44 +56,72 @@ public class EasyMail {
|
||||||
LocalDateTime timestamp = LocalDateTime.now();
|
LocalDateTime timestamp = LocalDateTime.now();
|
||||||
Email newEmail = new Email(sender, receiver, subject, content, timestamp);
|
Email newEmail = new Email(sender, receiver, subject, content, timestamp);
|
||||||
sender.getUsermail().getSentFolder().addEmail(newEmail);
|
sender.getUsermail().getSentFolder().addEmail(newEmail);
|
||||||
receiver.getUsermail().getInbox().addEmail(newEmail);
|
return receiver.getUsermail().getInbox().addEmail(newEmail);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
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 {
|
public boolean removeEmailFromInbox(String subject) throws Exception {
|
||||||
if (subject.trim().isEmpty())
|
if (subject.trim().isEmpty())
|
||||||
throw new IllegalArgumentException("Subject field is required!");
|
throw new IllegalArgumentException("Subject field is required!");
|
||||||
|
|
||||||
if (!this.currentUser.getUsermail().getStatus())
|
if (!this.currentUser.getUsermail().getStatus())
|
||||||
throw new IllegalStateException("No user is currently logged in!");
|
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);
|
return this.currentUser.getUsermail().getTrashFolder().addEmail(removedEmail);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeEmailFromSentFolder(String subject) throws Exception {
|
public boolean removeEmailFromSentFolder(String subject) throws Exception {
|
||||||
if (subject.trim().isEmpty())
|
if (subject.trim().isEmpty())
|
||||||
throw new IllegalArgumentException("Subject field is required!");
|
throw new IllegalArgumentException("Subject field is required!");
|
||||||
|
|
||||||
if (!this.currentUser.getUsermail().getStatus())
|
if (!this.currentUser.getUsermail().getStatus())
|
||||||
throw new IllegalStateException("No user is currently logged in!");
|
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);
|
return this.currentUser.getUsermail().getTrashFolder().addEmail(removedEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeEmailFromTrash(String subject) throws Exception {
|
public void removeEmailFromTrash(String subject) throws Exception {
|
||||||
if (subject.trim().isEmpty())
|
if (subject.trim().isEmpty())
|
||||||
throw new IllegalArgumentException("Subject field is required!");
|
throw new IllegalArgumentException("Subject field is required!");
|
||||||
|
|
||||||
if (!this.currentUser.getUsermail().getStatus())
|
if (!this.currentUser.getUsermail().getStatus())
|
||||||
throw new IllegalStateException("No user is currently logged in!");
|
throw new IllegalStateException("No user is currently logged in!");
|
||||||
|
|
||||||
this.currentUser.getUsermail().getTrashFolder().removeEmail(subject);
|
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;
|
package domain.email;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface EmailFolder {
|
public interface EmailFolder {
|
||||||
|
|
||||||
boolean addEmail(Email email);
|
boolean addEmail(Email email);
|
||||||
|
@ -7,5 +9,5 @@ public interface EmailFolder {
|
||||||
Email getEmailBySubject(String subject) throws EmailNotFoundException ;
|
Email getEmailBySubject(String subject) throws EmailNotFoundException ;
|
||||||
int getNumberOfEmails();
|
int getNumberOfEmails();
|
||||||
boolean clearAllEmails();
|
boolean clearAllEmails();
|
||||||
String[] listAllEmails();
|
ArrayList<Email>listAllEmails();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,12 +57,9 @@ public class Inbox implements EmailFolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] listAllEmails() {
|
public ArrayList<Email> listAllEmails() {
|
||||||
String[] subjects = new String[receivedEmails.size()];
|
return new ArrayList<>(receivedEmails); // sichere Kopie
|
||||||
for (int i = 0; i < receivedEmails.size(); i++) {
|
|
||||||
subjects[i] = receivedEmails.get(i).getSubject();
|
|
||||||
}
|
|
||||||
return subjects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,8 @@ public class SentFolder implements EmailFolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] listAllEmails() {
|
public ArrayList<Email> listAllEmails() {
|
||||||
String[] subjects = new String[emails.size()];
|
return new ArrayList<>(emails);
|
||||||
for (int i = 0; i < emails.size(); i++)
|
|
||||||
subjects[i] = emails.get(i).toString();
|
|
||||||
|
|
||||||
return subjects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,12 +56,8 @@ public class TrashFolder implements EmailFolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] listAllEmails() {
|
public ArrayList<Email> listAllEmails() {
|
||||||
String[] subjects = new String[removedEmails.size()];
|
return new ArrayList<>(removedEmails);
|
||||||
for (int i = 0; i < removedEmails.size(); i++)
|
|
||||||
subjects[i] = removedEmails.get(i).toString();
|
|
||||||
|
|
||||||
return subjects;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue