'Test multiple emails.'

def test_multiple_emails(self):

    states = []
    test_message1 = email.message.Message()
    test_message1['From'] = 'sender@test.com'
    test_message1['Subject'] = 'Test'
    test_message1['Date'] = datetime.datetime(2016, 1, 1, 12, 44, 57)
    test_message1.set_payload('Test    Message')
    test_message2 = email.message.Message()
    test_message2['From'] = 'sender@test.com'
    test_message2['Subject'] = 'Test    2'
    test_message2['Date'] = datetime.datetime(2016, 1, 1, 12, 44, 57)
    test_message2.set_payload('Test    Message    2')
    def state_changed_listener(entity_id, from_s, to_s):
        states.append(to_s)
    track_state_change(self.hass, ['sensor.emailtest'], state_changed_listener)
    sensor = imap_email_content.EmailContentSensor(self.hass, FakeEMailReader(deque([test_message1, test_message2])), 'test_emails_sensor', ['sender@test.com'], None)
    sensor.entity_id = 'sensor.emailtest'
    sensor.schedule_update_ha_state(True)
    self.hass.block_till_done()
    sensor.schedule_update_ha_state(True)
    self.hass.block_till_done()
    self.assertEqual('Test    Message', states[0].state)
    self.assertEqual('Test    Message    2', states[1].state)
    self.assertEqual('Test    Message    2', sensor.state)
