Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.*;
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.InputStream;
- import java.io.PrintStream;
- import org.junit.Before;
- import org.junit.Ignore;
- import org.junit.Test;
- public class CompanyEmailSystemTest extends CompanyEmailSystem {
- private final ByteArrayOutputStream testOutputContent = new ByteArrayOutputStream();
- @Before
- public void setUpStreams() {
- System.setOut(new PrintStream(testOutputContent));
- }
- @Ignore
- public void testListProjects() {
- // Test 1: Test that projects are listed and formatted correctly. Should pass.
- // Written by Marek Canavan, James Abbott, Richard Thomas and Matthew Carter
- // BUG FIX: Added a space to improve formatting.
- InputStream inputContent = new ByteArrayInputStream("P".getBytes());
- System.setIn(inputContent);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "1) Proj1 [Design] - 4 emails\n" +
- "2) Proj2 [Design] - 3 emails\n" +
- "3) Proj3 [Design] - 3 emails\n" +
- "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it Software\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent, receivedContent);
- }
- @Ignore
- public void testAddProject() {
- // Test 2: Test that project is added and formatted correctly. Should pass.
- // Written by Marek Canavan, James Abbott, Richard Thomas and Matthew Carter
- // No Bug Fixes.
- InputStream inputContent1 = new ByteArrayInputStream("A \rProject Nottingham\r P".getBytes());
- System.setIn(inputContent1);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "What is the title of the project?\n" +
- "[Project added]\n" +
- "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it Software\n" +
- "1) Proj1 [Design] - 4 emails\n" +
- "2) Proj2 [Design] - 3 emails\n" +
- "3) Proj3 [Design] - 3 emails\n" +
- "4) Project Nottingham [Design] - 0 emails\n" +
- "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it Software\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent, receivedContent);
- }
- @Ignore
- public void testListEmails() {
- // Test 3: Test that function returns correct email for given phase. Should pass.
- // Written by Marek Canavan, James Abbott
- // BUG FIX: Previously could not access project 1, as it was being used as the escape case, so changed the escape case to -99.
- InputStream inputContent1 = new ByteArrayInputStream("1\rL".getBytes());
- System.setIn(inputContent1);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "Proj1 [Design]\n" +
- "\n" +
- " From Subject\n" +
- "--------------------------------\n" +
- "1) me9@me.com - this is a test subject for email9\n" +
- "2) me6@me.com - this is a test subject for email6\n" +
- "3) me3@me.com - this is a test subject for email3\n" +
- "4) me0@me.com - this is a test subject for email0\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent, receivedContent);
- }
- @Ignore
- public void testListContacts() {
- // Test 4: Test that contacts are listed and formatted correctly. Should pass.
- // Written by Marek Canavan, James Abbott
- // No Bug Fix
- InputStream inputContent = new ByteArrayInputStream("P\r2\rC".getBytes()); // Enters 'p' into console to get past initial phase
- System.setIn(inputContent);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "1) Proj1 [Design] - 4 emails\n" +
- "2) Proj2 [Design] - 3 emails\n" +
- "3) Proj3 [Design] - 3 emails\n" +
- "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it Software\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "1) me1@me.com\n" +
- "2) me4@me.com\n" +
- "3) me7@me.com\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent, receivedContent);
- }
- @Ignore
- public void testChangeProjectPhase() {
- // Test 5: Test that Project can have it's phase increased and stopped when it reaches the maximum. Should pass.
- // Written by Marek Canavan, James Abbott
- // BUG FIX: See nextPhase() in CompanyProject.
- InputStream inputContent = new ByteArrayInputStream("2\rN\rN\rN\rN\rN".getBytes()); // Enters 'p' into console to get past initial phase
- System.setIn(inputContent);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "[Phase changed: Proj2 [Implementation]\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "[Phase changed: Proj2 [Testing]\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "[Phase changed: Proj2 [Deployment]\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "[Phase changed: Proj2 [Completed]\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "Project already in last phase.\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent, receivedContent);
- }
- @Ignore
- // Test 6: Test that phases are listed and formatted correctly. Should pass.
- // Written by Matthew and Richard
- // BUG FIX: Incorrectly had an x as a parameter for getEmailsForPhase when it doesn't take a parameter.
- public void testListPhases() {
- InputStream inputContent = new ByteArrayInputStream("2\rF".getBytes());
- System.setIn(inputContent);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "1) Design - 3 Emails\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent,receivedContent);
- }
- @Ignore
- // Test 7: Test if email is added and formatted correctly. Should pass.
- // Written by Matthew and Richard
- // No Bug Fix
- public void testAddEmail() {
- InputStream inputContent = new ByteArrayInputStream("2\rA\rfrom@email.com\rto@email.com\rsubject\rmessage\rL".getBytes());
- System.setIn(inputContent);
- CompanyEmailSystem.main(null);
- String expectedContent = "What do you want to do?\n" +
- " P = List [P]rojects, [num] = Open Project [num], A = [A]dd Project, X = E[x]it\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "Which email address is it from?\n" +
- "Which email address is it to?\n" +
- "What is the Subject?\n" +
- "What is the Message?\n" +
- "[Email added to Proj2 [Design]]\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n" +
- "Proj2 [Design]\n" +
- "\n" +
- " From Subject\n" +
- "--------------------------------\n" +
- "1) from@email.com - subject\n" +
- "2) me7@me.com - this is a test subject for email7\n" +
- "3) me4@me.com - this is a test subject for email4\n" +
- "4) me1@me.com - this is a test subject for email1\n" +
- "What do you want to do?\n" +
- " L = [L]ist Emails, A = [A]dd Email, F = List Phase [F]olders, N = Move to [N]ext Phase, [num] = List Emails in Phase [num], C = List [C]ontacts, X = E[x]it Project\n";
- String receivedContent = testOutputContent.toString();
- expectedContent.replaceAll("\\s", "");
- receivedContent.replaceAll("\\s", "");
- assertEquals(expectedContent,receivedContent);
- }
- }
Add Comment
Please, Sign In to add comment