Bump mon from 1.2.0 to 2.0.0 (#43)

This commit is contained in:
dependabot[bot] 2018-10-15 21:13:17 +00:00 committed by GitHub
parent 3dfde2aef6
commit 5802bf729e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 24 deletions

View file

@ -4,10 +4,8 @@ CHANGELOG
0.5.1 0.5.1
----- -----
* Bump mockito-core from 2.21.0 to 2.22.0 (#36) * Bump mon from 0.12.0 to 2.0.0 (#38)(#41)(#43)
* Bump mon from 0.12.0 to 1.1.0 (#38) * Bump mockito-core from 2.21.0 to 2.23.0 (#36)(#40)
* Bump mockito-core from 2.22.0 to 2.23.0 (#40)
* Bump mon from 1.1.0 to 1.2.0 (#41)
* Bump kemitix-parent from 5.1.1 to 5.2.0 (#39) * Bump kemitix-parent from 5.1.1 to 5.2.0 (#39)
0.5.0 0.5.0

View file

@ -49,7 +49,7 @@
<jacoco-class-line-covered-ratio>0</jacoco-class-line-covered-ratio> <jacoco-class-line-covered-ratio>0</jacoco-class-line-covered-ratio>
<jacoco-class-instruction-covered-ratio>0</jacoco-class-instruction-covered-ratio> <jacoco-class-instruction-covered-ratio>0</jacoco-class-instruction-covered-ratio>
<jacoco-class-missed-count-maximum>1</jacoco-class-missed-count-maximum> <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> </properties>
<dependencies> <dependencies>

View file

@ -22,6 +22,7 @@
package net.kemitix.wiser.assertions; package net.kemitix.wiser.assertions;
import net.kemitix.mon.maybe.Maybe; import net.kemitix.mon.maybe.Maybe;
import net.kemitix.mon.result.Result;
import org.subethamail.wiser.Wiser; import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage; import org.subethamail.wiser.WiserMessage;
@ -31,7 +32,10 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier; 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.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeMultipart;
@ -234,11 +238,7 @@ public final class WiserAssertions {
private Maybe<String> contentAsMultiPartMime(final Object content) { private Maybe<String> contentAsMultiPartMime(final Object content) {
if (content instanceof MimeMultipart) { if (content instanceof MimeMultipart) {
try { return mimeMultipartAsString((MimeMultipart) content);
return Maybe.just(getMimeMultipartAsString((MimeMultipart) content));
} catch (MessagingException | IOException e) {
throw new RuntimeException(e);
}
} }
return Maybe.nothing(); return Maybe.nothing();
} }
@ -264,22 +264,39 @@ public final class WiserAssertions {
* @param mimeMultipart the message part to convert * @param mimeMultipart the message part to convert
* *
* @return the message part as a string * @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) private Maybe<String> mimeMultipartAsString(final MimeMultipart mimeMultipart) {
throws MessagingException, IOException { return Result.toMaybe(Result.of(mimeMultipart::getCount)
final StringBuilder sb = new StringBuilder(); .map(count -> bodyPartsAsString(mimeMultipart, count)));
for (int i = 0; i < mimeMultipart.getCount(); i++) { }
Object content = mimeMultipart.getBodyPart(i).getContent();
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) { if (content instanceof MimeMultipart) {
sb.append(getMimeMultipartAsString((MimeMultipart) content)); return Result.of(() -> mimeMultipartAsString((MimeMultipart) content).orElse(""));
} else { } else {
sb.append(content); return Result.ok((String) content);
} }
} }
return sb.toString();
}
} }