Rename exception and update test

This commit is contained in:
Philip Whitehouse 2016-11-21 12:46:40 +00:00
parent d220b29a2b
commit 3e6625dd24
7 changed files with 17 additions and 17 deletions

View file

@ -59,7 +59,7 @@ public class MessageExtractor {
} else {
throw new MessagingException("Provided invalid part: " + part);
}
} catch (UnsupportedEncodingException e) {
} catch (UnsupportedContentTransferEncodingException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
} catch (IOException e) {
Log.e(LOG_TAG, "Unable to getTextFromPart", e);
@ -70,7 +70,7 @@ public class MessageExtractor {
}
private static String getTextFromTextPart(Part part, Body body, String mimeType, long textSizeLimit)
throws IOException, MessagingException, UnsupportedEncodingException {
throws IOException, MessagingException, UnsupportedContentTransferEncodingException {
/*
* We've got a text part, so let's see if it needs to be processed further.
*/

View file

@ -1018,7 +1018,7 @@ public class MimeUtility {
* The ultimate goal is to get to a point where all classes retain the original data and {@code RawDataBody} can be
* merged into {@link Body}.
*/
public static InputStream decodeBody(Body body) throws MessagingException, UnsupportedEncodingException {
public static InputStream decodeBody(Body body) throws MessagingException, UnsupportedContentTransferEncodingException {
InputStream inputStream;
if (body instanceof RawDataBody) {
RawDataBody rawDataBody = (RawDataBody) body;
@ -1044,7 +1044,7 @@ public class MimeUtility {
}
};
} else {
throw new UnsupportedEncodingException(encoding);
throw new UnsupportedContentTransferEncodingException(encoding);
}
} else {
inputStream = body.getInputStream();

View file

@ -0,0 +1,7 @@
package com.fsck.k9.mail.internet;
public class UnsupportedContentTransferEncodingException extends Exception {
public UnsupportedContentTransferEncodingException(String encoding) {
super("Unsupported encoding: "+encoding);
}
}

View file

@ -1,7 +0,0 @@
package com.fsck.k9.mail.internet;
public class UnsupportedEncodingException extends Exception {
public UnsupportedEncodingException(String encoding) {
super("Unsupported encoding: "+encoding);
}
}

View file

@ -72,13 +72,13 @@ public class MessageExtractorTest {
assertNull(result);
}
@Test(expected = UnsupportedOperationException.class)
public void getTextFromPart_withUnknownEncoding_shouldThrowRuntimeException() throws Exception {
@Test
public void getTextFromPart_withUnknownEncoding_shouldReturnNull() throws Exception {
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
BinaryMemoryBody body = new BinaryMemoryBody("Sample text body".getBytes(), "unknown encoding");
part.setBody(body);
MessageExtractor.getTextFromPart(part);
assertNull(MessageExtractor.getTextFromPart(part));
}
@Test

View file

@ -128,7 +128,7 @@ public class MimeMessageParseTest {
"");
}
@Test(expected = UnsupportedEncodingException.class)
@Test(expected = UnsupportedContentTransferEncodingException.class)
public void testSinglePartUnknownEncoding_throwsUnsupportedEncodingException() throws Exception {
MimeMessage msg = parseWithoutRecurse(toStream(
"From: <adam@example.org>\r\n" +

View file

@ -32,7 +32,7 @@ import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.internet.MimeMultipart;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.mail.internet.UnsupportedEncodingException;
import com.fsck.k9.mail.internet.UnsupportedContentTransferEncodingException;
import com.fsck.k9.message.MessageBuilder.Callback;
import com.fsck.k9.view.RecipientSelectView.Recipient;
import org.apache.commons.io.IOUtils;
@ -508,7 +508,7 @@ public class PgpMessageBuilderTest {
InputStream inputStream = MimeUtility.decodeBody(signatureBodyPart.getBody());
IOUtils.copy(inputStream, bos);
Assert.assertEquals(reason, expected, new String(bos.toByteArray()));
} catch (IOException | MessagingException | UnsupportedEncodingException e) {
} catch (IOException | MessagingException | UnsupportedContentTransferEncodingException e) {
Assert.fail();
}
}