0cf8e0c09f3b49b954fd76f8404c7816c14e1e5d
[james-jsieve.git] / core / src / test / java / org / apache / jsieve / DiscardTest.java
1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20 package org.apache.jsieve;
21
22 import org.apache.jsieve.exception.SieveException;
23 import org.apache.jsieve.exception.SyntaxException;
24 import org.apache.jsieve.mail.MailAdapter;
25 import org.apache.jsieve.parser.generated.ParseException;
26 import org.apache.jsieve.utils.JUnitUtils;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 /**
31 * Class DiscardTest
32 */
33 public class DiscardTest {
34
35 /**
36 * Test for Command 'discard' with invalid arguments
37 */
38 @org.junit.Test
39 public void testInvalidArguments() {
40 boolean isTestPassed = false;
41 String script = "discard 1 ;";
42
43 try {
44 JUnitUtils.interpret(JUnitUtils.createMail(), script);
45 } catch (SyntaxException e) {
46 isTestPassed = true;
47 } catch (ParseException e) {
48 } catch (SieveException e) {
49 }
50 Assert.assertTrue(isTestPassed);
51 }
52
53 /**
54 * Test for Command 'discard' with an invalid block
55 */
56 @Test
57 public void testInvalidBlock() {
58 boolean isTestPassed = false;
59 String script = "discard 1 {throwTestException;}";
60
61 try {
62 JUnitUtils.interpret(JUnitUtils.createMail(), script);
63 } catch (SyntaxException e) {
64 isTestPassed = true;
65 } catch (ParseException e) {
66 } catch (SieveException e) {
67 }
68 Assert.assertTrue(isTestPassed);
69 }
70
71 /*
72 * Test for Command 'discard'
73 */
74 @Test
75 public void testDiscard() {
76 boolean isTestPassed = false;
77 String script = "discard;";
78
79 try {
80 MailAdapter mail = JUnitUtils.createMail();
81 JUnitUtils.interpret(mail, script);
82 Assert.assertTrue(mail.getActions().isEmpty());
83 isTestPassed = true;
84 } catch (ParseException e) {
85 } catch (SieveException e) {
86 }
87 Assert.assertTrue(isTestPassed);
88 }
89
90 }