Commit dfc851b6259129425fdfe5970e96b4bb383320e5
1 parent
1154ae17
Exists in
master
Correção dos testes do MessageContext
Showing
3 changed files
with
152 additions
and
18 deletions
Show diff stats
impl/core/src/test/java/message/DummyMessageAppender.java
0 → 100644
... | ... | @@ -0,0 +1,62 @@ |
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
37 | +package message; | |
38 | + | |
39 | +import java.util.ArrayList; | |
40 | +import java.util.List; | |
41 | + | |
42 | +import javax.enterprise.context.RequestScoped; | |
43 | + | |
44 | +import br.gov.frameworkdemoiselle.internal.implementation.MessageAppender; | |
45 | +import br.gov.frameworkdemoiselle.message.Message; | |
46 | + | |
47 | +@RequestScoped | |
48 | +public class DummyMessageAppender implements MessageAppender { | |
49 | + | |
50 | + private static final long serialVersionUID = 1L; | |
51 | + | |
52 | + private List<Message> messages = new ArrayList<Message>(); | |
53 | + | |
54 | + @Override | |
55 | + public void append(Message message) { | |
56 | + messages.add(message); | |
57 | + } | |
58 | + | |
59 | + public List<Message> getMessages() { | |
60 | + return messages; | |
61 | + } | |
62 | +} | ... | ... |
impl/core/src/test/java/message/MessageContextTest.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package message; |
2 | 38 | |
3 | 39 | import static junit.framework.Assert.assertEquals; |
... | ... | @@ -46,8 +82,10 @@ public class MessageContextTest { |
46 | 82 | public void testAddMessageWithoutParams() { |
47 | 83 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
48 | 84 | Message message = new DefaultMessage("Menssage without param"); |
85 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
86 | + | |
49 | 87 | messageContext.add(message); |
50 | - assertEquals(messageContext.getMessages().size(), 1); | |
88 | + assertEquals(appender.getMessages().size(), 1); | |
51 | 89 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
52 | 90 | } |
53 | 91 | |
... | ... | @@ -55,8 +93,10 @@ public class MessageContextTest { |
55 | 93 | public void testAddMessageWithoutParamsIfSeverityIsInfo() { |
56 | 94 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
57 | 95 | Message message = new DefaultMessage("Menssage without param"); |
96 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
97 | + | |
58 | 98 | messageContext.add(message); |
59 | - assertEquals(messageContext.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
99 | + assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
60 | 100 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
61 | 101 | } |
62 | 102 | |
... | ... | @@ -64,8 +104,10 @@ public class MessageContextTest { |
64 | 104 | public void testAddMessageWitSeverityInfo() { |
65 | 105 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
66 | 106 | Message message = new DefaultMessage("Menssage without param", SeverityType.INFO); |
107 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
108 | + | |
67 | 109 | messageContext.add(message); |
68 | - assertEquals(messageContext.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
110 | + assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.INFO); | |
69 | 111 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
70 | 112 | } |
71 | 113 | |
... | ... | @@ -73,8 +115,10 @@ public class MessageContextTest { |
73 | 115 | public void testAddMessageWitSeverityWarn() { |
74 | 116 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
75 | 117 | Message message = new DefaultMessage("Menssage without param", SeverityType.WARN); |
118 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
119 | + | |
76 | 120 | messageContext.add(message); |
77 | - assertEquals(messageContext.getMessages().get(0).getSeverity(), SeverityType.WARN); | |
121 | + assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.WARN); | |
78 | 122 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
79 | 123 | } |
80 | 124 | |
... | ... | @@ -82,19 +126,10 @@ public class MessageContextTest { |
82 | 126 | public void testAddMessageWitSeverityErro() { |
83 | 127 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
84 | 128 | Message message = new DefaultMessage("Menssage without param", SeverityType.ERROR); |
85 | - messageContext.add(message); | |
86 | - assertEquals(messageContext.getMessages().get(0).getSeverity(), SeverityType.ERROR); | |
87 | - ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
88 | - } | |
129 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
89 | 130 | |
90 | - @Test | |
91 | - public void testCleanMessageContext() { | |
92 | - ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
93 | - Message message = new DefaultMessage("Menssage without param"); | |
94 | 131 | messageContext.add(message); |
95 | - assertEquals(messageContext.getMessages().size(), 1); | |
96 | - messageContext.clear(); | |
97 | - assertEquals(messageContext.getMessages().size(), 0); | |
132 | + assertEquals(appender.getMessages().get(0).getSeverity(), SeverityType.ERROR); | |
98 | 133 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
99 | 134 | } |
100 | 135 | |
... | ... | @@ -102,8 +137,10 @@ public class MessageContextTest { |
102 | 137 | public void testRecoverMessageWithParams() { |
103 | 138 | ContextManager.activate(ManagedContext.class, RequestScoped.class); |
104 | 139 | Message message = new DefaultMessage("Message with {0} param"); |
140 | + DummyMessageAppender appender = Beans.getReference(DummyMessageAppender.class); | |
141 | + | |
105 | 142 | messageContext.add(message, 1); |
106 | - assertTrue(messageContext.getMessages().get(0).getText().equals("Message with 1 param")); | |
143 | + assertTrue(appender.getMessages().get(0).getText().equals("Message with 1 param")); | |
107 | 144 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
108 | 145 | } |
109 | 146 | |
... | ... | @@ -134,5 +171,4 @@ public class MessageContextTest { |
134 | 171 | Assert.assertEquals(expected, value); |
135 | 172 | ContextManager.deactivate(ManagedContext.class, RequestScoped.class); |
136 | 173 | } |
137 | - | |
138 | 174 | } | ... | ... |
impl/core/src/test/java/message/MessageWithResourceBundle.java
1 | +/* | |
2 | + * Demoiselle Framework | |
3 | + * Copyright (C) 2010 SERPRO | |
4 | + * ---------------------------------------------------------------------------- | |
5 | + * This file is part of Demoiselle Framework. | |
6 | + * | |
7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
9 | + * as published by the Free Software Foundation. | |
10 | + * | |
11 | + * This program is distributed in the hope that it will be useful, | |
12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | + * GNU General Public License for more details. | |
15 | + * | |
16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | + * ---------------------------------------------------------------------------- | |
21 | + * Este arquivo é parte do Framework Demoiselle. | |
22 | + * | |
23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
25 | + * do Software Livre (FSF). | |
26 | + * | |
27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
30 | + * para maiores detalhes. | |
31 | + * | |
32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
36 | + */ | |
1 | 37 | package message; |
2 | 38 | |
3 | 39 | import javax.inject.Inject; |
4 | 40 | |
5 | 41 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
6 | 42 | |
7 | -public class MessageWithResourceBundle{ | |
43 | +public class MessageWithResourceBundle { | |
8 | 44 | |
9 | 45 | @Inject |
10 | 46 | private ResourceBundle bundle; | ... | ... |