Bump mon from 1.2.0 to 2.0.0 (#43)
This commit is contained in:
parent
3dfde2aef6
commit
5802bf729e
3 changed files with 39 additions and 24 deletions
|
@ -4,10 +4,8 @@ CHANGELOG
|
|||
0.5.1
|
||||
-----
|
||||
|
||||
* Bump mockito-core from 2.21.0 to 2.22.0 (#36)
|
||||
* Bump mon from 0.12.0 to 1.1.0 (#38)
|
||||
* Bump mockito-core from 2.22.0 to 2.23.0 (#40)
|
||||
* Bump mon from 1.1.0 to 1.2.0 (#41)
|
||||
* Bump mon from 0.12.0 to 2.0.0 (#38)(#41)(#43)
|
||||
* Bump mockito-core from 2.21.0 to 2.23.0 (#36)(#40)
|
||||
* Bump kemitix-parent from 5.1.1 to 5.2.0 (#39)
|
||||
|
||||
0.5.0
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -49,7 +49,7 @@
|
|||
<jacoco-class-line-covered-ratio>0</jacoco-class-line-covered-ratio>
|
||||
<jacoco-class-instruction-covered-ratio>0</jacoco-class-instruction-covered-ratio>
|
||||
<jacoco-class-missed-count-maximum>1</jacoco-class-missed-count-maximum>
|
||||
<mon.version>1.2.0</mon.version>
|
||||
<mon.version>2.0.0</mon.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
package net.kemitix.wiser.assertions;
|
||||
|
||||
import net.kemitix.mon.maybe.Maybe;
|
||||
import net.kemitix.mon.result.Result;
|
||||
import org.subethamail.wiser.Wiser;
|
||||
import org.subethamail.wiser.WiserMessage;
|
||||
|
||||
|
@ -31,7 +32,10 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
@ -234,11 +238,7 @@ public final class WiserAssertions {
|
|||
|
||||
private Maybe<String> contentAsMultiPartMime(final Object content) {
|
||||
if (content instanceof MimeMultipart) {
|
||||
try {
|
||||
return Maybe.just(getMimeMultipartAsString((MimeMultipart) content));
|
||||
} catch (MessagingException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return mimeMultipartAsString((MimeMultipart) content);
|
||||
}
|
||||
return Maybe.nothing();
|
||||
}
|
||||
|
@ -264,22 +264,39 @@ public final class WiserAssertions {
|
|||
* @param mimeMultipart the message part to convert
|
||||
*
|
||||
* @return the message part as a string
|
||||
*
|
||||
* @throws MessagingException if the part is empty
|
||||
* @throws IOException if there is another error
|
||||
*/
|
||||
private String getMimeMultipartAsString(final MimeMultipart mimeMultipart)
|
||||
throws MessagingException, IOException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < mimeMultipart.getCount(); i++) {
|
||||
Object content = mimeMultipart.getBodyPart(i).getContent();
|
||||
private Maybe<String> mimeMultipartAsString(final MimeMultipart mimeMultipart) {
|
||||
return Result.toMaybe(Result.of(mimeMultipart::getCount)
|
||||
.map(count -> bodyPartsAsString(mimeMultipart, count)));
|
||||
}
|
||||
|
||||
private String bodyPartsAsString(final MimeMultipart mimeMultipart, final int count) {
|
||||
return IntStream.range(0, count)
|
||||
.mapToObj(i -> bodyPart(mimeMultipart, i))
|
||||
.map(this::bodyPartAsString)
|
||||
.map(Result::orElseThrowUnchecked)
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
|
||||
private Result<String> bodyPartAsString(final Result<BodyPart> bodyPart) {
|
||||
return bodyPartContent(bodyPart)
|
||||
.flatMap(this::contentObjectAsString);
|
||||
}
|
||||
|
||||
private Result<Object> bodyPartContent(final Result<BodyPart> bodyPart) {
|
||||
return bodyPart.flatMap(part -> Result.of(part::getContent));
|
||||
}
|
||||
|
||||
private Result<BodyPart> bodyPart(final MimeMultipart mimeMultipart, final int i) {
|
||||
return Result.of(() -> mimeMultipart.getBodyPart(i));
|
||||
}
|
||||
|
||||
private Result<String> contentObjectAsString(final Object content) {
|
||||
if (content instanceof MimeMultipart) {
|
||||
sb.append(getMimeMultipartAsString((MimeMultipart) content));
|
||||
return Result.of(() -> mimeMultipartAsString((MimeMultipart) content).orElse(""));
|
||||
} else {
|
||||
sb.append(content);
|
||||
return Result.ok((String) content);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue