1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve;
21
22 import junit.framework.TestCase;
23
24 import org.apache.jsieve.commands.ThrowTestException;
25 import org.apache.jsieve.exception.SieveException;
26 import org.apache.jsieve.exception.SyntaxException;
27 import org.apache.jsieve.mail.ActionKeep;
28 import org.apache.jsieve.mail.MailAdapter;
29 import org.apache.jsieve.parser.generated.ParseException;
30 import org.apache.jsieve.utils.JUnitUtils;
31
32
33
34
35 public class StopTest extends TestCase {
36
37
38
39
40 public void testStop() {
41 boolean isTestPassed = false;
42 String script = "stop; throwTestException;";
43
44 try {
45 MailAdapter mail = JUnitUtils.createMail();
46 JUnitUtils.interpret(mail, script);
47 assertTrue(mail.getActions().size() == 1);
48 assertTrue(mail.getActions().get(0) instanceof ActionKeep);
49 isTestPassed = true;
50 } catch (ThrowTestException.TestException e) {
51 } catch (ParseException e) {
52 } catch (SieveException e) {
53 }
54 assertTrue(isTestPassed);
55 }
56
57
58
59
60 public void testInvalidArguments() {
61 boolean isTestPassed = false;
62 String script = "stop 1 ;";
63
64 try {
65 JUnitUtils.interpret(JUnitUtils.createMail(), script);
66 } catch (SyntaxException e) {
67 isTestPassed = true;
68 } catch (ParseException e) {
69 } catch (SieveException e) {
70 }
71 assertTrue(isTestPassed);
72 }
73
74
75
76
77 public void testInvalidBlock() {
78 boolean isTestPassed = false;
79 String script = "stop 1 {throwTestException;}";
80
81 try {
82 JUnitUtils.interpret(JUnitUtils.createMail(), script);
83 } catch (SyntaxException e) {
84 isTestPassed = true;
85 } catch (ParseException e) {
86 } catch (SieveException e) {
87 }
88 assertTrue(isTestPassed);
89 }
90
91 }