Repository: james-jsieve Updated Branches: refs/heads/master ffeccf9af -> 94c2bc292
JSIEVE-108 Discard instruction should emmit a ActionDiscard Project: http://git-wip-us.apache.org/repos/asf/james-jsieve/repo Commit: http://git-wip-us.apache.org/repos/asf/james-jsieve/commit/94c2bc29 Tree: http://git-wip-us.apache.org/repos/asf/james-jsieve/tree/94c2bc29 Diff: http://git-wip-us.apache.org/repos/asf/james-jsieve/diff/94c2bc29 Branch: refs/heads/master Commit: 94c2bc2923f9b545b2b930f46abe34058273c15b Parents: ffeccf9 Author: benwa <[email protected]> Authored: Sat May 6 17:21:17 2017 +0700 Committer: benwa <[email protected]> Committed: Thu May 11 17:43:12 2017 +0700 ---------------------------------------------------------------------- .../org/apache/jsieve/commands/Discard.java | 4 ++ .../org/apache/jsieve/mail/ActionDiscard.java | 28 ++++++++ .../java/org/apache/jsieve/DiscardTest.java | 75 +++++++------------- 3 files changed, 58 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-jsieve/blob/94c2bc29/core/src/main/java/org/apache/jsieve/commands/Discard.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/jsieve/commands/Discard.java b/core/src/main/java/org/apache/jsieve/commands/Discard.java index e55cf9b..2696fb7 100644 --- a/core/src/main/java/org/apache/jsieve/commands/Discard.java +++ b/core/src/main/java/org/apache/jsieve/commands/Discard.java @@ -23,6 +23,7 @@ import org.apache.jsieve.Arguments; import org.apache.jsieve.Block; import org.apache.jsieve.SieveContext; import org.apache.jsieve.exception.SieveException; +import org.apache.jsieve.mail.ActionDiscard; import org.apache.jsieve.mail.MailAdapter; /** @@ -54,6 +55,9 @@ public class Discard extends AbstractActionCommand { // Just cancels the implicit keep // See http://tools.ietf.org/html/rfc5228#section-4.4 context.getCommandStateManager().setImplicitKeep(false); + + mail.addAction(new ActionDiscard()); + return null; } http://git-wip-us.apache.org/repos/asf/james-jsieve/blob/94c2bc29/core/src/main/java/org/apache/jsieve/mail/ActionDiscard.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/jsieve/mail/ActionDiscard.java b/core/src/main/java/org/apache/jsieve/mail/ActionDiscard.java new file mode 100644 index 0000000..1d4e191 --- /dev/null +++ b/core/src/main/java/org/apache/jsieve/mail/ActionDiscard.java @@ -0,0 +1,28 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.jsieve.mail; + +/** + * Class ActionDiscard encapsulates the information required to discard a mail. See + * RFC 3028, Section 4.4. + */ +public class ActionDiscard implements Action { + +} http://git-wip-us.apache.org/repos/asf/james-jsieve/blob/94c2bc29/core/src/test/java/org/apache/jsieve/DiscardTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/jsieve/DiscardTest.java b/core/src/test/java/org/apache/jsieve/DiscardTest.java index 0cf8e0c..580cd09 100644 --- a/core/src/test/java/org/apache/jsieve/DiscardTest.java +++ b/core/src/test/java/org/apache/jsieve/DiscardTest.java @@ -19,72 +19,49 @@ package org.apache.jsieve; -import org.apache.jsieve.exception.SieveException; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.jsieve.exception.SyntaxException; +import org.apache.jsieve.mail.Action; +import org.apache.jsieve.mail.ActionDiscard; import org.apache.jsieve.mail.MailAdapter; -import org.apache.jsieve.parser.generated.ParseException; import org.apache.jsieve.utils.JUnitUtils; -import org.junit.Assert; +import org.assertj.core.api.Condition; import org.junit.Test; -/** - * Class DiscardTest - */ public class DiscardTest { - /** - * Test for Command 'discard' with invalid arguments - */ - @org.junit.Test - public void testInvalidArguments() { - boolean isTestPassed = false; + private static final Condition<Action> INSTANCE_OF_ACTION_DISCARDED = new Condition<Action>() { + @Override + public boolean matches(Action action) { + return action instanceof ActionDiscard; + } + }; + + @Test(expected = SyntaxException.class) + public void discardShouldThrowOnInvalidArguments() throws Exception { String script = "discard 1 ;"; - try { - JUnitUtils.interpret(JUnitUtils.createMail(), script); - } catch (SyntaxException e) { - isTestPassed = true; - } catch (ParseException e) { - } catch (SieveException e) { - } - Assert.assertTrue(isTestPassed); + JUnitUtils.interpret(JUnitUtils.createMail(), script); } - /** - * Test for Command 'discard' with an invalid block - */ - @Test - public void testInvalidBlock() { - boolean isTestPassed = false; - String script = "discard 1 {throwTestException;}"; + @Test(expected = SyntaxException.class) + public void discardShouldThrowOnInvalidFollowingBlock() throws Exception { + String script = "discard {throwTestException;}"; - try { - JUnitUtils.interpret(JUnitUtils.createMail(), script); - } catch (SyntaxException e) { - isTestPassed = true; - } catch (ParseException e) { - } catch (SieveException e) { - } - Assert.assertTrue(isTestPassed); + JUnitUtils.interpret(JUnitUtils.createMail(), script); } - /* - * Test for Command 'discard' - */ @Test - public void testDiscard() { - boolean isTestPassed = false; + public void discardShouldAddOnlyActionDiscard() throws Exception { String script = "discard;"; - try { - MailAdapter mail = JUnitUtils.createMail(); - JUnitUtils.interpret(mail, script); - Assert.assertTrue(mail.getActions().isEmpty()); - isTestPassed = true; - } catch (ParseException e) { - } catch (SieveException e) { - } - Assert.assertTrue(isTestPassed); + MailAdapter mail = JUnitUtils.createMail(); + JUnitUtils.interpret(mail, script); + + assertThat(mail.getActions()) + .hasSize(1) + .are(INSTANCE_OF_ACTION_DISCARDED); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
