Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #281 from Cognifide/243-email-dependencies-check
Browse files Browse the repository at this point in the history
243 email dependencies check
  • Loading branch information
mkrzyzanowski committed Sep 10, 2018
2 parents 4f05062 + f1fcee0 commit c4cfdf1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 37 deletions.
4 changes: 0 additions & 4 deletions bb-email/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>

<!-- logging -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
*/
package com.cognifide.qa.bb.email;

import java.time.LocalDateTime;
import java.util.function.Predicate;

import org.joda.time.DateTime;

/**
* This class offers several EmailData predicates.
*/
public final class CommonEmailDataPredicates {

private CommonEmailDataPredicates() {}
private CommonEmailDataPredicates() {
}

/**
* A predicate that matches an email message with a given reception time.
*
* @param dateTime preceding the email received attribute
* @param localDateTime preceding the email received attribute
* @return Predicate for emails with received attribute after specific point in time
*/
public static Predicate<EmailData> isReceivedAfter(final DateTime dateTime) {
public static Predicate<EmailData> isReceivedAfter(final LocalDateTime localDateTime) {
return emailData -> {
if (emailData == null) {
return false;
} else {
return emailData.getReceivedDateTime().isAfter(dateTime);
return emailData.getReceivedDateTime().isAfter(localDateTime);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
*/
package com.cognifide.qa.bb.email;

import java.time.LocalDateTime;
import java.util.Objects;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.joda.time.DateTime;

/**
* This class represents email message.
*/
public class EmailData {

private DateTime receivedDateTime;
private LocalDateTime receivedDateTime;

private String messageContent;

Expand Down Expand Up @@ -58,7 +58,7 @@ public void setMessageContent(String messageContent) {
/**
* @return Email message receive DateTime.
*/
public DateTime getReceivedDateTime() {
public LocalDateTime getReceivedDateTime() {
return receivedDateTime;
}

Expand All @@ -67,7 +67,7 @@ public DateTime getReceivedDateTime() {
*
* @param receivedDateTime received date of email
*/
public void setReceivedDateTime(DateTime receivedDateTime) {
public void setReceivedDateTime(LocalDateTime receivedDateTime) {
this.receivedDateTime = receivedDateTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package com.cognifide.qa.bb.email;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -29,7 +31,6 @@
import javax.mail.Multipart;
import javax.mail.Part;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -70,7 +71,7 @@ public EmailData create(Message message) {
String subject = getSubjectString(message);
emailData.setSubject(subject);

DateTime receivedDateTime = getReceivedDate(message);
LocalDateTime receivedDateTime = getReceivedDate(message);
emailData.setReceivedDateTime(receivedDateTime);
emailData.setAddressFrom(getAddressFrom(message));
emailData.setAddressTo(getAddressTo(message));
Expand Down Expand Up @@ -104,8 +105,9 @@ private String matchEmailAddress(String text) {
}
}

private DateTime getReceivedDate(Message message) throws MessagingException {
return new DateTime(message.getReceivedDate());
private LocalDateTime getReceivedDate(Message message) throws MessagingException {
return message.getReceivedDate() != null ? message.getReceivedDate().toInstant()
.atZone(ZoneId.systemDefault()).toLocalDateTime() : LocalDateTime.now();
}

private String getSubjectString(Message message) throws MessagingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import static org.junit.Assert.assertEquals;

import java.time.LocalDateTime;
import java.util.function.Predicate;

import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
Expand All @@ -34,23 +34,23 @@
@RunWith(Theories.class)
public class CommonEmailDataPredicatesTest {

private static final DateTime RECEIVED_DATE = new DateTime(2010, 2, 14, 17, 00);
private static final LocalDateTime RECEIVED_DATE = LocalDateTime.of(
2010, 2, 14, 17, 0);

private EmailData sampleEmailData;

@DataPoints(value = "isReceivedAfter")
public static Object[][] forIsReceivedAfter() {
return new Object[][] {
{new DateTime(1999, 1, 1, 0, 0), true},
{null, false},
{new DateTime(2010, 2, 14, 16, 59), true},
{new DateTime(2010, 2, 14, 17, 00), false}
return new Object[][]{
{LocalDateTime.of(1999, 1, 1, 0, 0), true},
{LocalDateTime.of(2010, 2, 14, 16, 59), true},
{LocalDateTime.of(2010, 2, 14, 17, 0), false}
};
}

@DataPoints(value = "containsText")
public static Object[][] forContainsText() {
return new Object[][] {
return new Object[][]{
{"sample", true},
{"sample message content", true},
{"", true},
Expand All @@ -61,7 +61,7 @@ public static Object[][] forContainsText() {

@DataPoints(value = "emails")
public static Object[][] forEmailTests() {
return new Object[][] {
return new Object[][]{
// email, isSender, isRecipient
{"alice@example.com", true, false},
{"bob@example.com", false, true},
Expand All @@ -83,7 +83,7 @@ public void createObjectsForTests() {
@Theory
public void isReceivedAfter(@FromDataPoints("isReceivedAfter") Object[] dataPoint) {
// given
DateTime dateTime = (DateTime) dataPoint[0];
LocalDateTime dateTime = (LocalDateTime) dataPoint[0];
boolean expected = (boolean) dataPoint[1];
// when
Predicate<EmailData> predicate = CommonEmailDataPredicates.isReceivedAfter(dateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private EmailData createEmailData(String subject, String message) {
emailData.setAddressTo(addressTo);
emailData.setMessageContent(message);
emailData.setSubject(subject);
emailData.setReceivedDateTime(emailData.getReceivedDateTime());
return emailData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
*/
package com.cognifide.qa.bb.module;

import static com.google.common.base.Throwables.throwIfUnchecked;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.io.Resources;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
Expand All @@ -43,7 +44,8 @@ protected void configure() {
try {
Names.bindProperties(binder(), getProperties());
} catch (IOException e) {
Throwables.propagate(e);
throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ limitations under the License.
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.version>0.7.7.201606060606</jacoco.version>
<selenium.version>3.14.0</selenium.version>
<guice.version>3.0</guice.version>
<guice.version>4.2.0</guice.version>
<cucumber.version>1.2.3</cucumber.version>
<version.logback>1.1.7</version.logback>
</properties>
Expand Down Expand Up @@ -180,17 +180,17 @@ limitations under the License.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.3.3</version>
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
<version>26.0-jre</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
Expand Down Expand Up @@ -227,7 +227,7 @@ limitations under the License.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.4</version>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down Expand Up @@ -270,7 +270,7 @@ limitations under the License.
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.10.0</version>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -288,7 +288,7 @@ limitations under the License.
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>1.5.0</version>
<version>1.5.3</version>
<scope>test</scope>
</dependency>

Expand Down

0 comments on commit c4cfdf1

Please sign in to comment.