Skip to content

Commit

Permalink
#295, #322: Switched to David Moten's subethasmtp fork which updates …
Browse files Browse the repository at this point in the history
…the abandoned project with Java 8 and Jakarta 2.x.x (see https://github.com/davidmoten/subethasmtp). Simple Java Mail uses the SMTP test harness Wiser from the project.
  • Loading branch information
bbottema committed Dec 28, 2021
1 parent 11cf1b7 commit e6ffafb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
10 changes: 2 additions & 8 deletions modules/simple-java-mail/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,10 @@
<scope>test</scope>
</dependency>
<dependency><!-- SMTP test server -->
<groupId>org.subethamail</groupId>
<groupId>com.github.davidmoten</groupId>
<artifactId>subethasmtp</artifactId>
<version>3.1.7</version>
<version>6.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;

import static java.lang.String.format;
Expand All @@ -26,16 +25,14 @@
* The {@link Wiser} instance can be directly retrieved but also only from inside a JUnit statement.
*/
public class SmtpServerRule extends ExternalResource {
private final Wiser wiser = new Wiser();
private final int port;
private final Wiser wiser;

public SmtpServerRule(@NotNull Integer port) {
this.port = port;
this.wiser = Wiser.accepter((from, recipient) -> true).port(port);
}

@Override
protected void before() {
this.wiser.setPort(port);
this.wiser.start();
}

Expand All @@ -62,12 +59,9 @@ public MimeMessage getOnlyMessage(String envelopeReceiver)
checkState("getMessages()");
List<WiserMessage> messages = getMessages();
assertThat(messages).hasSize(1);
Iterator<WiserMessage> iterator = messages.iterator();
WiserMessage wiserMessage = iterator.next();
WiserMessage wiserMessage = messages.remove(0);
assertThat(wiserMessage.getEnvelopeReceiver()).isEqualTo(envelopeReceiver);
MimeMessage mimeMessage = wiserMessage.getMimeMessage();
iterator.remove();
return mimeMessage;
return wiserMessage.getMimeMessage();
}

@NotNull
Expand All @@ -76,9 +70,7 @@ public MimeMessageAndEnvelope getOnlyMessage()
checkState("getMessages()");
List<WiserMessage> messages = getMessages();
assertThat(messages).hasSize(1);
Iterator<WiserMessage> iterator = messages.iterator();
WiserMessage wiserMessage = iterator.next();
iterator.remove();
WiserMessage wiserMessage = messages.remove(0);
return new MimeMessageAndEnvelope(wiserMessage.getMimeMessage(), wiserMessage.getEnvelopeSender());
}

Expand All @@ -87,16 +79,14 @@ public MimeMessage getMessage(String envelopeReceiver)
throws MessagingException {
checkState("getMessages()");
List<WiserMessage> messages = getMessages();
Iterator<WiserMessage> iterator = messages.iterator();
while (iterator.hasNext()) {
WiserMessage wiserMessage = iterator.next();
if (wiserMessage.getEnvelopeReceiver().equals(envelopeReceiver)) {
MimeMessage mimeMessage = wiserMessage.getMimeMessage();
iterator.remove();
return mimeMessage;
}
}
throw new AssertionError("message not found for recipient " + envelopeReceiver);

WiserMessage wiserMessage = messages.stream()
.filter(m->m.getEnvelopeReceiver().equals(envelopeReceiver))
.findFirst()
.orElseThrow(() -> new AssertionError("message not found for recipient " + envelopeReceiver));

messages.remove(wiserMessage);
return wiserMessage.getMimeMessage();
}

@NotNull
Expand Down

0 comments on commit e6ffafb

Please sign in to comment.