@Test(expected = RuntimeException.class)
 public void attendeeWhoDoesntExistTriesToDecline() {
   fakeMeeting.setFrom("*****@*****.**");
   fakeMeeting.setAttendees("*****@*****.**");
   sm.setup(fakeMeeting);
   sm.setDeclined("*****@*****.**");
 }
  @Test
  public void twoAttendeesInvited() {
    fakeMeeting.setFrom("*****@*****.**");
    fakeMeeting.setAttendees("[email protected]; [email protected]");
    sm.setup(fakeMeeting);

    ArrayList<String> invited = (ArrayList<String>) sm.getUnAnsweredRecipients();
    assertEquals(2, invited.size());
  }
  @Test
  public void twoAttendeesInvitedOneAccepts() {
    fakeMeeting.setFrom("*****@*****.**");
    fakeMeeting.setAttendees("[email protected]; [email protected]");
    sm.setup(fakeMeeting);
    sm.setAccepted("*****@*****.**");

    ArrayList<String> invited = (ArrayList<String>) sm.getUnAnsweredRecipients();
    assertEquals(1, invited.size());
    assertTrue("*****@*****.**".equals(invited.get(0)));

    ArrayList<String> accepted = (ArrayList<String>) sm.getAcceptedRecipients();
    assertEquals(2, accepted.size());
    assertTrue("*****@*****.**".equals(accepted.get(0)));
    assertTrue("*****@*****.**".equals(accepted.get(1)));
  }
  /** This thread accepts email, change-set, acknowledgement etc. */
  public void run() {
    logger.info("Accepting Emails from this client: " + emailAddress);
    while (true) {
      try {
        // Receiving objects
        // handle meeting request
        Object obj = SuperCECServer.getEmailToObjectInputStream().get(emailAddress).readObject();

        if (obj instanceof Email) {
          // handle emails
          boolean emailAdded = false;

          EmailImpl e = (EmailImpl) obj;
          if (!e.isMeetingEmail()) {
            emailAdded = SuperCECServer.getArrivingEmailQueue().add(e);
            logger.info("Is Email " + e.getSubject() + " added to Queue: " + emailAdded);

          } else {
            logger.info(
                "Going to build a Meeting object from the email meeting invitation"
                    + e.getSubject());
            Meeting meeting = buildMeeting(e);
            MeetingDataWrapper md = new MeetingDataWrapper();
            md.id = meeting.getId(); //
            md.meetingObj = meeting; //

            ServerMeetingData serverMeetingData = new ServerMeetingDataImpl();
            serverMeetingData.setup(meeting);
            md.meetingData = serverMeetingData; //

            SuperCECServer.getMeetingMap().put(meeting.getId(), md);

            emailAdded = SuperCECServer.getArrivingEmailQueue().add(e);
            logger.info("Is Email " + e.getSubject() + " added to Queue: " + emailAdded);
          }

          // Send the acknowledgement regarless if we recieved an email or an email invitation to a
          // meeting
          logger.info(
              "CECServer Sending Ack to : "
                  + emailAddress
                  + " for email subject: "
                  + e.getSubject());
          Ack ack = new Ack(e.getId(), MessageType.EMAIL);
          SuperCECServer.getEmailToObjectOutputStream().get(emailAddress).writeObject(ack);

        } else if ((obj instanceof Ack)) {
          // handle acks
          Ack ack = (Ack) obj;
          handleAck(ack);
          // delete the thing that we were saving for this ack (regular email, email for meeting,
          // or changeset)

        } else if ((obj instanceof CommunicationChangeSet)) {
          CommunicationChangeSet ccs = (CommunicationChangeSet) obj;
          applyChangeSetToMeetingMap(emailAddress, ccs);
        }
      } catch (SocketException e) {
        logger.info(emailAddress + " is Disconnected from the server!");
        break;
      } catch (EOFException e) {
        logger.info(emailAddress + " Disconnected from the server!");
        break;
      } catch (Exception e) {
        logger.info(emailAddress + " Disconnected from the server!");
        logger.severe(StackTrace.asString(e));
        break;
      }
    }
  }
 @Test(expected = RuntimeException.class)
 public void poorlyFormattedAttendees() {
   fakeMeeting.setFrom("*****@*****.**");
   fakeMeeting.setAttendees("a@@b.com; [email protected]");
   sm.setup(fakeMeeting);
 }