From 24bdd39790893e7e608d9b00aabcc1d8d65b9554 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 3 Dec 2012 12:40:21 +0200 Subject: [PATCH] INT-2846: ImapMailReceiverTests: fix OS newLine * Add `trim()` to the actual value * Remove '\n' from expected value * Remove redundant Mocks JIRA: https://jira.springsource.org/browse/INT-2846 --- .../mail/ImapMailReceiverTests.java | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java index 185d32b323..2562ab0409 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java @@ -74,6 +74,7 @@ import com.sun.mail.imap.IMAPMessage; /** * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan */ public class ImapMailReceiverTests { @@ -622,13 +623,7 @@ public class ImapMailReceiverTests { Folder folder = mock(Folder.class); when(folder.exists()).thenReturn(true); when(folder.isOpen()).thenReturn(true); - final AtomicBoolean closed = new AtomicBoolean(); - doAnswer(new Answer (){ - public Object answer(InvocationOnMock invocation) throws Throwable { - closed.set(true); - return null; - } - }).when(folder).close(Mockito.anyBoolean()); + IMAPMessage message = mock(IMAPMessage.class); when(folder.search((SearchTerm) Mockito.any())).thenReturn(new Message[]{message}); when(store.getFolder(Mockito.any(URLName.class))).thenReturn(folder); @@ -637,20 +632,6 @@ public class ImapMailReceiverTests { df.setPropertyValue("store", store); receiver.afterPropertiesSet(); - Multipart multiPart = mock(Multipart.class); - when(multiPart.getCount()).thenReturn(1); - when(message.getContent()).thenReturn(multiPart); - final BodyPart bodyPart = mock(BodyPart.class); - doAnswer(new Answer(){ - - public Object answer(InvocationOnMock invocation) throws Throwable { - if (closed.get()) { - throw new IOException("Folder is closed"); - } - return bodyPart; - } - }).when(multiPart).getBodyPart(Mockito.anyInt()); - when(bodyPart.getContent()).thenReturn("bar"); doAnswer(new Answer () { public Object answer(InvocationOnMock invocation) throws Throwable { @@ -661,7 +642,7 @@ public class ImapMailReceiverTests { }).when(message).writeTo(Mockito.any(OutputStream.class)); Message[] messages = receiver.receive(); Object content = messages[0].getContent(); - assertEquals("bar\n", ((Multipart) content).getBodyPart(0).getContent()); + assertEquals("bar", ((Multipart) content).getBodyPart(0).getContent().toString().trim()); assertSame(folder, messages[0].getFolder()); }