Skip to content

Commit acf9dea

Browse files
committed
Specify the method signature in a method that might throw an exception (part 2)
1 parent b7c7c9f commit acf9dea

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailStartingBuilderImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ public EmailPopulatingBuilder copying(@NotNull final Email email) {
209209
if (email.getSentDate() != null) {
210210
builder.fixingSentDate(email.getSentDate());
211211
}
212+
if (email.getPkcs12ConfigForSmimeSigning() != null) {
213+
builder.signWithSmime(email.getPkcs12ConfigForSmimeSigning());
214+
}
215+
if (email.getX509CertificateForSmimeEncryption() != null) {
216+
builder.encryptWithSmime(email.getX509CertificateForSmimeEncryption());
217+
}
212218
if (email.getDkimConfig() != null) {
213219
builder.signWithDomainKey(email.getDkimConfig());
214220
}

modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/ImmutableDelegatingSMTPMessageTest.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public void testIrrelevantGettersAndAllowedMutatorsAreDelegatedProperly() throws
171171
verify(mockMmessage).saveChanges();
172172
}
173173

174+
@SuppressWarnings("Convert2MethodRef")
174175
@Test
175176
public void testImmutability() throws IOException {
176177
Email email = createDummyEmailBuilder("<id>", true, false, true, true, true, false, false).buildEmail();
@@ -184,47 +185,47 @@ public void testImmutability() throws IOException {
184185
assertThatThrownBy(subject::updateHeaders).hasMessageContaining("protected in the delegate");
185186
assertThatThrownBy(() -> subject.createInternetHeaders(new ByteArrayInputStream(new byte[]{}))).hasMessageContaining("protected in the delegate");
186187
assertThatThrownBy(() -> subject.createMimeMessage(Session.getDefaultInstance(new Properties()))).hasMessageContaining("protected in the delegate");
187-
assertThatThrownBy(() -> subject.setEnvelopeFrom("from")).hasMessage("Further mutation is not allowed");
188-
assertThatThrownBy(() -> subject.setNotifyOptions(3)).hasMessage("Further mutation is not allowed");
189-
assertThatThrownBy(() -> subject.setReturnOption(2)).hasMessage("Further mutation is not allowed");
190-
assertThatThrownBy(() -> subject.setAllow8bitMIME(false)).hasMessage("Further mutation is not allowed");
191-
assertThatThrownBy(() -> subject.setSendPartial(true)).hasMessage("Further mutation is not allowed");
192-
assertThatThrownBy(() -> subject.setSubmitter("submitter")).hasMessage("Further mutation is not allowed");
193-
assertThatThrownBy(() -> subject.setMailExtension("ext")).hasMessage("Further mutation is not allowed");
194-
assertThatThrownBy(() -> subject.setFrom(new InternetAddress())).hasMessage("Further mutation is not allowed");
195-
assertThatThrownBy(() -> subject.setFrom("value")).hasMessage("Further mutation is not allowed");
196-
assertThatThrownBy(subject::setFrom).hasMessage("Further mutation is not allowed");
197-
assertThatThrownBy(() -> subject.addFrom(new Address[]{})).hasMessage("Further mutation is not allowed");
198-
assertThatThrownBy(() -> subject.setSender(new InternetAddress())).hasMessage("Further mutation is not allowed");
199-
assertThatThrownBy(() -> subject.setRecipients(TO, new Address[]{})).hasMessage("Further mutation is not allowed");
200-
assertThatThrownBy(() -> subject.setRecipients(TO, "addresses")).hasMessage("Further mutation is not allowed");
201-
assertThatThrownBy(() -> subject.addRecipients(TO, new Address[]{})).hasMessage("Further mutation is not allowed");
202-
assertThatThrownBy(() -> subject.addRecipients(TO, "addresses")).hasMessage("Further mutation is not allowed");
203-
assertThatThrownBy(() -> subject.setReplyTo(new Address[]{})).hasMessage("Further mutation is not allowed");
204-
assertThatThrownBy(() -> subject.setSubject("subject")).hasMessage("Further mutation is not allowed");
205-
assertThatThrownBy(() -> subject.setSubject("subject", "UTF-8")).hasMessage("Further mutation is not allowed");
206-
assertThatThrownBy(() -> subject.setSentDate(new Date())).hasMessage("Further mutation is not allowed");
207-
assertThatThrownBy(() -> subject.setDisposition("disposition")).hasMessage("Further mutation is not allowed");
208-
assertThatThrownBy(() -> subject.setContentID("<id>")).hasMessage("Further mutation is not allowed");
209-
assertThatThrownBy(() -> subject.setContentMD5("md5")).hasMessage("Further mutation is not allowed");
210-
assertThatThrownBy(() -> subject.setDescription("description")).hasMessage("Further mutation is not allowed");
211-
assertThatThrownBy(() -> subject.setDescription("description", "UTF-8")).hasMessage("Further mutation is not allowed");
212-
assertThatThrownBy(() -> subject.setContentLanguage(new String[] {})).hasMessage("Further mutation is not allowed");
213-
assertThatThrownBy(() -> subject.setFileName("filename")).hasMessage("Further mutation is not allowed");
214-
assertThatThrownBy(() -> subject.setDataHandler(mock(DataHandler.class))).hasMessage("Further mutation is not allowed");
215-
assertThatThrownBy(() -> subject.setContent("content", "type")).hasMessage("Further mutation is not allowed");
216-
assertThatThrownBy(() -> subject.setText("text")).hasMessage("Further mutation is not allowed");
217-
assertThatThrownBy(() -> subject.setText("text", "UTF-8")).hasMessage("Further mutation is not allowed");
218-
assertThatThrownBy(() -> subject.setText("text", "UTF-8", "subtype")).hasMessage("Further mutation is not allowed");
219-
assertThatThrownBy(() -> subject.setContent(mock(Multipart.class))).hasMessage("Further mutation is not allowed");
220-
assertThatThrownBy(() -> subject.setHeader("name", "value")).hasMessage("Further mutation is not allowed");
221-
assertThatThrownBy(() -> subject.addHeader("name", "value")).hasMessage("Further mutation is not allowed");
222-
assertThatThrownBy(() -> subject.removeHeader("name")).hasMessage("Further mutation is not allowed");
223-
assertThatThrownBy(() -> subject.addHeaderLine("line")).hasMessage("Further mutation is not allowed");
224-
assertThatThrownBy(() -> subject.setFlags(mock(Flags.class), false)).hasMessage("Further mutation is not allowed");
225-
assertThatThrownBy(() -> subject.setRecipient(TO, new InternetAddress())).hasMessage("Further mutation is not allowed");
226-
assertThatThrownBy(() -> subject.addRecipient(TO, new InternetAddress())).hasMessage("Further mutation is not allowed");
227-
assertThatThrownBy(() -> subject.setFlag(ANSWERED, true)).hasMessage("Further mutation is not allowed");
188+
assertThatThrownBy(() -> subject.setEnvelopeFrom("from")).hasMessage("Further mutation is not allowed: setEnvelopeFrom(String)");
189+
assertThatThrownBy(() -> subject.setNotifyOptions(3)).hasMessage("Further mutation is not allowed: setNotifyOptions(int)");
190+
assertThatThrownBy(() -> subject.setReturnOption(2)).hasMessage("Further mutation is not allowed: setReturnOption(int)");
191+
assertThatThrownBy(() -> subject.setAllow8bitMIME(false)).hasMessage("Further mutation is not allowed: setAllow8bitMIME(boolean)");
192+
assertThatThrownBy(() -> subject.setSendPartial(true)).hasMessage("Further mutation is not allowed: setSendPartial(boolean)");
193+
assertThatThrownBy(() -> subject.setSubmitter("submitter")).hasMessage("Further mutation is not allowed: setSubmitter(String)");
194+
assertThatThrownBy(() -> subject.setMailExtension("ext")).hasMessage("Further mutation is not allowed: setMailExtension(String)");
195+
assertThatThrownBy(() -> subject.setFrom(new InternetAddress())).hasMessage("Further mutation is not allowed: setFrom(Address)");
196+
assertThatThrownBy(() -> subject.setFrom("value")).hasMessage("Further mutation is not allowed: setFrom(String)");
197+
assertThatThrownBy(() -> subject.setFrom()).hasMessage("Further mutation is not allowed: setFrom()");
198+
assertThatThrownBy(() -> subject.addFrom(new Address[]{})).hasMessage("Further mutation is not allowed: addFrom(Address[])");
199+
assertThatThrownBy(() -> subject.setSender(new InternetAddress())).hasMessage("Further mutation is not allowed: setSender(Address)");
200+
assertThatThrownBy(() -> subject.setRecipients(TO, new Address[]{})).hasMessage("Further mutation is not allowed: setRecipients(RecipientType, Address[])");
201+
assertThatThrownBy(() -> subject.setRecipients(TO, "addresses")).hasMessage("Further mutation is not allowed: setRecipients(RecipientType, String)");
202+
assertThatThrownBy(() -> subject.addRecipients(TO, new Address[]{})).hasMessage("Further mutation is not allowed: addRecipients(RecipientType, Address[])");
203+
assertThatThrownBy(() -> subject.addRecipients(TO, "addresses")).hasMessage("Further mutation is not allowed: addRecipients(RecipientType, String)");
204+
assertThatThrownBy(() -> subject.setReplyTo(new Address[]{})).hasMessage("Further mutation is not allowed: setReplyTo(Address[])");
205+
assertThatThrownBy(() -> subject.setSubject("subject")).hasMessage("Further mutation is not allowed: setSubject(String)");
206+
assertThatThrownBy(() -> subject.setSubject("subject", "UTF-8")).hasMessage("Further mutation is not allowed: setSubject(String, String)");
207+
assertThatThrownBy(() -> subject.setSentDate(new Date())).hasMessage("Further mutation is not allowed: setSentDate(Date)");
208+
assertThatThrownBy(() -> subject.setDisposition("disposition")).hasMessage("Further mutation is not allowed: setDisposition(String)");
209+
assertThatThrownBy(() -> subject.setContentID("<id>")).hasMessage("Further mutation is not allowed: setContentID(String)");
210+
assertThatThrownBy(() -> subject.setContentMD5("md5")).hasMessage("Further mutation is not allowed: setContentMD5(String)");
211+
assertThatThrownBy(() -> subject.setDescription("description")).hasMessage("Further mutation is not allowed: setDescription(String)");
212+
assertThatThrownBy(() -> subject.setDescription("description", "UTF-8")).hasMessage("Further mutation is not allowed: setDescription(String, String)");
213+
assertThatThrownBy(() -> subject.setContentLanguage(new String[] {})).hasMessage("Further mutation is not allowed: setContentLanguage(String[])");
214+
assertThatThrownBy(() -> subject.setFileName("filename")).hasMessage("Further mutation is not allowed: setFileName(String)");
215+
assertThatThrownBy(() -> subject.setDataHandler(mock(DataHandler.class))).hasMessage("Further mutation is not allowed: setDataHandler(DataHandler)");
216+
assertThatThrownBy(() -> subject.setContent("content", "type")).hasMessage("Further mutation is not allowed: setContent(Object, String)");
217+
assertThatThrownBy(() -> subject.setText("text")).hasMessage("Further mutation is not allowed: setText(String)");
218+
assertThatThrownBy(() -> subject.setText("text", "UTF-8")).hasMessage("Further mutation is not allowed: setText(String, String)");
219+
assertThatThrownBy(() -> subject.setText("text", "UTF-8", "subtype")).hasMessage("Further mutation is not allowed: setText(String, String, String)");
220+
assertThatThrownBy(() -> subject.setContent(mock(Multipart.class))).hasMessage("Further mutation is not allowed: setContent(Multipart)");
221+
assertThatThrownBy(() -> subject.setHeader("name", "value")).hasMessage("Further mutation is not allowed: setHeader(String, String)");
222+
assertThatThrownBy(() -> subject.addHeader("name", "value")).hasMessage("Further mutation is not allowed: addHeader(String, String)");
223+
assertThatThrownBy(() -> subject.removeHeader("name")).hasMessage("Further mutation is not allowed: removeHeader(String)");
224+
assertThatThrownBy(() -> subject.addHeaderLine("line")).hasMessage("Further mutation is not allowed: addHeaderLine(String)");
225+
assertThatThrownBy(() -> subject.setFlags(mock(Flags.class), false)).hasMessage("Further mutation is not allowed: setFlags(Flags, boolean)");
226+
assertThatThrownBy(() -> subject.setRecipient(TO, new InternetAddress())).hasMessage("Further mutation is not allowed: setRecipient(RecipientType, Address)");
227+
assertThatThrownBy(() -> subject.addRecipient(TO, new InternetAddress())).hasMessage("Further mutation is not allowed: addRecipient(RecipientType, Address)");
228+
assertThatThrownBy(() -> subject.setFlag(ANSWERED, true)).hasMessage("Further mutation is not allowed: setFlag(Flag, boolean)");
228229
}
229230

230231
private static class HeaderExtractor implements Extractor<Header, String> {

0 commit comments

Comments
 (0)