CAMEL-7873 Fixed the CS errors
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5eed4d96 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5eed4d96 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5eed4d96 Branch: refs/heads/master Commit: 5eed4d9668ab055749b9f0305b019b779a236a5c Parents: 0785013 Author: Willem Jiang <[email protected]> Authored: Mon Oct 20 11:51:22 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Mon Oct 20 11:51:22 2014 +0800 ---------------------------------------------------------------------- .../camel/component/mail/MailEndpoint.java | 15 ++-- .../apache/camel/component/mail/MailSorter.java | 9 ++- .../camel/component/mail/MailSortTermTest.java | 19 +++-- .../camel/component/mail/MailSorterTest.java | 75 ++++++++++---------- 4 files changed, 61 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5eed4d96/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java index 1a6b34f..63531aa 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java @@ -16,8 +16,16 @@ */ package org.apache.camel.component.mail; +import javax.mail.Message; +import javax.mail.search.SearchTerm; + import com.sun.mail.imap.SortTerm; -import org.apache.camel.*; + +import org.apache.camel.Consumer; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Processor; +import org.apache.camel.Producer; import org.apache.camel.impl.DefaultExchange; import org.apache.camel.impl.DefaultHeaderFilterStrategy; import org.apache.camel.impl.ScheduledPollEndpoint; @@ -25,9 +33,6 @@ import org.apache.camel.spi.HeaderFilterStrategy; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; -import javax.mail.Message; -import javax.mail.search.SearchTerm; - /** * Endpoint for Camel Mail. */ @@ -196,7 +201,7 @@ public class MailEndpoint extends ScheduledPollEndpoint { * @param sortTerm {@link #getSortTerm()} */ public void setSortTerm(SortTerm[] sortTerm) { - this.sortTerm = (sortTerm == null ? null : sortTerm.clone()); + this.sortTerm = sortTerm == null ? null : sortTerm.clone(); } /** http://git-wip-us.apache.org/repos/asf/camel/blob/5eed4d96/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailSorter.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailSorter.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailSorter.java index cdfb22c..e5c91c3 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailSorter.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailSorter.java @@ -16,12 +16,17 @@ */ package org.apache.camel.component.mail; -import com.sun.mail.imap.SortTerm; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.List; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; -import java.util.*; + +import com.sun.mail.imap.SortTerm; /** * Utility class for sorting of mail messages http://git-wip-us.apache.org/repos/asf/camel/blob/5eed4d96/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java index 40fb2f5..70154e4 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSortTermTest.java @@ -16,24 +16,21 @@ */ package org.apache.camel.component.mail; -import com.sun.mail.imap.SortTerm; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.impl.JndiRegistry; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; -import org.jvnet.mock_javamail.Mailbox; +import java.util.Date; import javax.mail.Folder; import javax.mail.Message; import javax.mail.Store; -import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -import javax.mail.search.SearchTerm; -import java.util.Date; +import com.sun.mail.imap.SortTerm; -import static org.apache.camel.component.mail.SearchTermBuilder.Op; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; +import org.jvnet.mock_javamail.Mailbox; /** * This is a test that checks integration of the sort term in camel. The actual sorting logic is tested in the http://git-wip-us.apache.org/repos/asf/camel/blob/5eed4d96/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java index a2a0b52..7e47b81 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java @@ -16,17 +16,17 @@ */ package org.apache.camel.component.mail; -import com.sun.mail.imap.SortTerm; -import org.apache.camel.component.mail.MailSorter; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; -import org.mockito.Mockito; +import java.util.Date; import javax.mail.Address; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; -import java.util.Date; + +import com.sun.mail.imap.SortTerm; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; +import org.mockito.Mockito; import static org.mockito.Mockito.when; @@ -35,29 +35,26 @@ import static org.mockito.Mockito.when; * Tests mail sort util */ public class MailSorterTest extends CamelTestSupport { - private final static Message[] messages = new Message[3]; - private final static Message tieBreaker; + private static final Message[] MESSAGES = new Message[3]; + private static final Message TIE_BREAKER; /** * All possible sort terms */ - private final static SortTerm[] possibleTerms = new SortTerm[]{ - SortTerm.ARRIVAL, - SortTerm.CC, - SortTerm.DATE, - SortTerm.FROM, - SortTerm.SIZE, - SortTerm.TO, - SortTerm.SUBJECT - }; + private static final SortTerm[] POSSIBLE_TERMS = + new SortTerm[] { + SortTerm.ARRIVAL, SortTerm.CC, + SortTerm.DATE, SortTerm.FROM, + SortTerm.SIZE, SortTerm.TO, + SortTerm.SUBJECT}; static { try { - messages[0] = createMessage("to1", "cc1", "from1", new Date(1), new Date(1001), 1, "subject1"); - messages[1] = createMessage("to2", "cc2", "from2", new Date(2), new Date(1002), 2, "subject2"); - messages[2] = createMessage("to3", "cc3", "from3", new Date(3), new Date(1003), 3, "subject3"); + MESSAGES[0] = createMessage("to1", "cc1", "from1", new Date(1), new Date(1001), 1, "subject1"); + MESSAGES[1] = createMessage("to2", "cc2", "from2", new Date(2), new Date(1002), 2, "subject2"); + MESSAGES[2] = createMessage("to3", "cc3", "from3", new Date(3), new Date(1003), 3, "subject3"); // Message that creates a tie on all fields except for one - tieBreaker = createMessage("to3", "cc3", "from3", new Date(3), new Date(1003), 3, "subject0TieBreaker"); + TIE_BREAKER = createMessage("to3", "cc3", "from3", new Date(3), new Date(1003), 3, "subject0TieBreaker"); } catch (MessagingException e) { // Rethrow as unchecked. Can not occur anyways throw new IllegalStateException(e); @@ -68,7 +65,7 @@ public class MailSorterTest extends CamelTestSupport { * Create a new message with the specified data */ private static Message createMessage(String to, String cc, String from, Date received, Date sent, int size, String subject) - throws MessagingException { + throws MessagingException { final Message msg = Mockito.mock(Message.class); when(msg.getFrom()).thenReturn(new Address[]{new InternetAddress(from)}); when(msg.getRecipients(Message.RecipientType.TO)).thenReturn(new Address[]{new InternetAddress(to)}); @@ -82,11 +79,11 @@ public class MailSorterTest extends CamelTestSupport { @Test public void testSortMessages() throws Exception { - Message[] expected = new Message[]{messages[0], messages[1], messages[2]}; + Message[] expected = new Message[]{MESSAGES[0], MESSAGES[1], MESSAGES[2]}; // Sort using all the terms. Message order should be the same no matter what term is used - for (SortTerm term : possibleTerms) { - Message[] actual = messages.clone(); + for (SortTerm term : POSSIBLE_TERMS) { + Message[] actual = MESSAGES.clone(); MailSorter.sortMessages(actual, new SortTerm[]{term}); try { assertArrayEquals(actual, expected); @@ -98,11 +95,11 @@ public class MailSorterTest extends CamelTestSupport { @Test public void testSortMessagesReverse() throws Exception { - Message[] expected = new Message[]{messages[2], messages[1], messages[0]}; + Message[] expected = new Message[]{MESSAGES[2], MESSAGES[1], MESSAGES[0]}; // Sort using all the terms. Message order should be the same no matter what term is used - for (SortTerm term : possibleTerms) { - Message[] actual = messages.clone(); + for (SortTerm term : POSSIBLE_TERMS) { + Message[] actual = MESSAGES.clone(); MailSorter.sortMessages(actual, new SortTerm[]{SortTerm.REVERSE, term}); try { assertArrayEquals(actual, expected); @@ -114,13 +111,13 @@ public class MailSorterTest extends CamelTestSupport { @Test public void testSortMessagesMulti() throws Exception { - Message[] expected = new Message[]{messages[0], messages[1], messages[2]}; + Message[] expected = new Message[]{MESSAGES[0], MESSAGES[1], MESSAGES[2]}; // Sort using all the terms. Message order should be the same no matter what term is used. The second term // should be ignored since it is already the decider. - for (SortTerm term1 : possibleTerms) { - for (SortTerm term2 : possibleTerms) { - Message[] actual = messages.clone(); + for (SortTerm term1 : POSSIBLE_TERMS) { + for (SortTerm term2 : POSSIBLE_TERMS) { + Message[] actual = MESSAGES.clone(); MailSorter.sortMessages(actual, new SortTerm[]{term1, SortTerm.REVERSE, term2}); try { assertArrayEquals(actual, expected); @@ -134,21 +131,21 @@ public class MailSorterTest extends CamelTestSupport { @Test public void testSortMessagesWithTie() throws Exception { - Message[] given = new Message[]{messages[2], tieBreaker}; + Message[] given = new Message[]{MESSAGES[2], TIE_BREAKER}; // Sort according to the whole list. Only the last element breaks the tie Message[] actual1 = given.clone(); - MailSorter.sortMessages(actual1, possibleTerms); - assertArrayEquals(actual1, new Message[]{tieBreaker, messages[2]}); + MailSorter.sortMessages(actual1, POSSIBLE_TERMS); + assertArrayEquals(actual1, new Message[]{TIE_BREAKER, MESSAGES[2]}); // now reverse the last element (the tie breaker) - SortTerm[] reversed = new SortTerm[possibleTerms.length + 1]; - System.arraycopy(possibleTerms, 0, reversed, 0, possibleTerms.length - 1); + SortTerm[] reversed = new SortTerm[POSSIBLE_TERMS.length + 1]; + System.arraycopy(POSSIBLE_TERMS, 0, reversed, 0, POSSIBLE_TERMS.length - 1); reversed[reversed.length - 2] = SortTerm.REVERSE; - reversed[reversed.length - 1] = possibleTerms[possibleTerms.length - 1]; + reversed[reversed.length - 1] = POSSIBLE_TERMS[POSSIBLE_TERMS.length - 1]; // And check again Message[] actual2 = given.clone(); MailSorter.sortMessages(actual2, reversed); - assertArrayEquals(actual2, new Message[]{messages[2], tieBreaker}); + assertArrayEquals(actual2, new Message[]{MESSAGES[2], TIE_BREAKER}); } } \ No newline at end of file
