Commit a14667b34a13f87db7c32e42e9ea8f0badb21f98
1 parent
e201247b
Exists in
master
Refatoração dos testes unitários
Showing
3 changed files
with
233 additions
and
275 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticatorTest.java
1 | -//package br.gov.frameworkdemoiselle.internal.implementation; | ||
2 | -// | ||
3 | -//import static org.easymock.EasyMock.expect; | ||
4 | -//import static org.junit.Assert.assertTrue; | ||
5 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | -//import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | -// | ||
8 | -//import java.util.Locale; | ||
9 | -// | ||
10 | -//import org.junit.After; | ||
11 | -//import org.junit.Before; | ||
12 | -//import org.junit.Test; | ||
13 | -//import org.junit.runner.RunWith; | ||
14 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | ||
15 | -//import org.powermock.modules.junit4.PowerMockRunner; | ||
16 | -// | ||
17 | -//import br.gov.frameworkdemoiselle.DemoiselleException; | ||
18 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
19 | -// | ||
20 | -///** | ||
21 | -// * @author SERPRO | ||
22 | -// * @see DefaultAuthenticator | ||
23 | -// */ | ||
24 | -//@RunWith(PowerMockRunner.class) | ||
25 | -//@PrepareForTest(CoreBundle.class) | ||
26 | -//public class DefaultAuthenticatorTest { | ||
27 | -// | ||
28 | -// private DefaultAuthenticator authenticator; | ||
29 | -// | ||
30 | -// @Before | ||
31 | -// public void setUp() throws Exception { | ||
32 | -// authenticator = new DefaultAuthenticator(); | ||
33 | -// | ||
34 | -// mockStatic(CoreBundle.class); | ||
35 | -// | ||
36 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
37 | -// expect(CoreBundle.get()).andReturn(bundle); | ||
38 | -// | ||
39 | -// replay(CoreBundle.class); | ||
40 | -// } | ||
41 | -// | ||
42 | -// @After | ||
43 | -// public void tearDown() { | ||
44 | -// authenticator = null; | ||
45 | -// } | ||
46 | -// | ||
47 | -// @Test | ||
48 | -// public void testAuthenticate() { | ||
49 | -// try { | ||
50 | -// authenticator.authenticate(); | ||
51 | -// } catch (Exception e) { | ||
52 | -// assertTrue(e instanceof DemoiselleException); | ||
53 | -// } | ||
54 | -// } | ||
55 | -// | ||
56 | -// @Test | ||
57 | -// public void testUnAuthenticate() { | ||
58 | -// try { | ||
59 | -// authenticator.unAuthenticate(); | ||
60 | -// } catch (Exception e) { | ||
61 | -// assertTrue(e instanceof DemoiselleException); | ||
62 | -// } | ||
63 | -// } | ||
64 | -// | ||
65 | -// @Test | ||
66 | -// public void testGetUser() { | ||
67 | -// try { | ||
68 | -// authenticator.getUser(); | ||
69 | -// } catch (Exception e) { | ||
70 | -// assertTrue(e instanceof DemoiselleException); | ||
71 | -// } | ||
72 | -// } | ||
73 | -// | ||
74 | -//} | 1 | +package br.gov.frameworkdemoiselle.internal.implementation; |
2 | + | ||
3 | +import static org.easymock.EasyMock.expect; | ||
4 | +import static org.junit.Assert.assertTrue; | ||
5 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | + | ||
8 | +import java.util.Locale; | ||
9 | + | ||
10 | +import org.junit.After; | ||
11 | +import org.junit.Before; | ||
12 | +import org.junit.Test; | ||
13 | +import org.junit.runner.RunWith; | ||
14 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
15 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
16 | + | ||
17 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
18 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
19 | + | ||
20 | +/** | ||
21 | + * @author SERPRO | ||
22 | + * @see DefaultAuthenticator | ||
23 | + */ | ||
24 | +@RunWith(PowerMockRunner.class) | ||
25 | +@PrepareForTest(Beans.class) | ||
26 | +public class DefaultAuthenticatorTest { | ||
27 | + | ||
28 | + private DefaultAuthenticator authenticator; | ||
29 | + | ||
30 | + @Before | ||
31 | + public void setUp() throws Exception { | ||
32 | + authenticator = new DefaultAuthenticator(); | ||
33 | + | ||
34 | + mockStatic(Beans.class); | ||
35 | + | ||
36 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
37 | + | ||
38 | + replay(Beans.class); | ||
39 | + } | ||
40 | + | ||
41 | + @After | ||
42 | + public void tearDown() { | ||
43 | + authenticator = null; | ||
44 | + } | ||
45 | + | ||
46 | + @Test | ||
47 | + public void testAuthenticate() { | ||
48 | + try { | ||
49 | + authenticator.authenticate(); | ||
50 | + } catch (Exception e) { | ||
51 | + assertTrue(e instanceof DemoiselleException); | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + @Test(expected = DemoiselleException.class) | ||
56 | + public void testUnAuthenticate() { | ||
57 | + authenticator.unAuthenticate(); | ||
58 | + } | ||
59 | + | ||
60 | + @Test(expected = DemoiselleException.class) | ||
61 | + public void testGetUser() { | ||
62 | + authenticator.getUser(); | ||
63 | + } | ||
64 | + | ||
65 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizerTest.java
1 | -//package br.gov.frameworkdemoiselle.internal.implementation; | ||
2 | -// | ||
3 | -//import static org.easymock.EasyMock.expect; | ||
4 | -//import static org.junit.Assert.assertTrue; | ||
5 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | -//import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | -// | ||
8 | -//import java.util.Locale; | ||
9 | -// | ||
10 | -//import org.junit.After; | ||
11 | -//import org.junit.Before; | ||
12 | -//import org.junit.Test; | ||
13 | -//import org.junit.runner.RunWith; | ||
14 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | ||
15 | -//import org.powermock.modules.junit4.PowerMockRunner; | ||
16 | -// | ||
17 | -//import br.gov.frameworkdemoiselle.DemoiselleException; | ||
18 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
19 | -// | ||
20 | -///** | ||
21 | -// * @author SERPRO | ||
22 | -// * @see DefaultAuthorizer | ||
23 | -// */ | ||
24 | -//@RunWith(PowerMockRunner.class) | ||
25 | -//@PrepareForTest(CoreBundle.class) | ||
26 | -//public class DefaultAuthorizerTest { | ||
27 | -// | ||
28 | -// private DefaultAuthorizer authorizer; | ||
29 | -// | ||
30 | -// @Before | ||
31 | -// public void setUp() throws Exception { | ||
32 | -// authorizer = new DefaultAuthorizer(); | ||
33 | -// | ||
34 | -// mockStatic(CoreBundle.class); | ||
35 | -// | ||
36 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
37 | -// expect(CoreBundle.get()).andReturn(bundle); | ||
38 | -// | ||
39 | -// replay(CoreBundle.class); | ||
40 | -// } | ||
41 | -// | ||
42 | -// @After | ||
43 | -// public void tearDown() { | ||
44 | -// authorizer = null; | ||
45 | -// } | ||
46 | -// | ||
47 | -// @Test | ||
48 | -// public void testHasRole() { | ||
49 | -// try { | ||
50 | -// authorizer.hasRole(null); | ||
51 | -// } catch (Exception e) { | ||
52 | -// assertTrue(e instanceof DemoiselleException); | ||
53 | -// } | ||
54 | -// } | ||
55 | -// | ||
56 | -// @Test | ||
57 | -// public void testHasPermission() { | ||
58 | -// try { | ||
59 | -// authorizer.hasPermission(null, null); | ||
60 | -// } catch (Exception e) { | ||
61 | -// assertTrue(e instanceof DemoiselleException); | ||
62 | -// } | ||
63 | -// } | ||
64 | -// | ||
65 | -//} | 1 | +package br.gov.frameworkdemoiselle.internal.implementation; |
2 | + | ||
3 | +import static org.easymock.EasyMock.expect; | ||
4 | +import static org.junit.Assert.assertTrue; | ||
5 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
6 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
7 | + | ||
8 | +import java.util.Locale; | ||
9 | + | ||
10 | +import org.junit.After; | ||
11 | +import org.junit.Before; | ||
12 | +import org.junit.Test; | ||
13 | +import org.junit.runner.RunWith; | ||
14 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
15 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
16 | + | ||
17 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
18 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
19 | + | ||
20 | +/** | ||
21 | + * @author SERPRO | ||
22 | + * @see DefaultAuthorizer | ||
23 | + */ | ||
24 | +@RunWith(PowerMockRunner.class) | ||
25 | +@PrepareForTest(Beans.class) | ||
26 | +public class DefaultAuthorizerTest { | ||
27 | + | ||
28 | + private DefaultAuthorizer authorizer; | ||
29 | + | ||
30 | + @Before | ||
31 | + public void setUp() throws Exception { | ||
32 | + authorizer = new DefaultAuthorizer(); | ||
33 | + | ||
34 | + mockStatic(Beans.class); | ||
35 | + | ||
36 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
37 | + | ||
38 | + replay(Beans.class); | ||
39 | + } | ||
40 | + | ||
41 | + @After | ||
42 | + public void tearDown() { | ||
43 | + authorizer = null; | ||
44 | + } | ||
45 | + | ||
46 | + @Test(expected = DemoiselleException.class) | ||
47 | + public void testHasRole() { | ||
48 | + authorizer.hasRole(null); | ||
49 | + } | ||
50 | + | ||
51 | + @Test(expected = DemoiselleException.class) | ||
52 | + public void testHasPermission() { | ||
53 | + authorizer.hasPermission(null, null); | ||
54 | + } | ||
55 | + | ||
56 | +} |
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransactionTest.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 | -// */ | ||
37 | -//package br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | -// | ||
39 | -//import static org.easymock.EasyMock.expect; | ||
40 | -//import static org.junit.Assert.assertTrue; | ||
41 | -//import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
42 | -//import static org.powermock.api.easymock.PowerMock.replay; | ||
43 | -// | ||
44 | -//import java.util.Locale; | ||
45 | -// | ||
46 | -//import org.junit.After; | ||
47 | -//import org.junit.Before; | ||
48 | -//import org.junit.Test; | ||
49 | -//import org.junit.runner.RunWith; | ||
50 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | ||
51 | -//import org.powermock.modules.junit4.PowerMockRunner; | ||
52 | -// | ||
53 | -//import br.gov.frameworkdemoiselle.DemoiselleException; | ||
54 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
55 | -// | ||
56 | -///** | ||
57 | -// * @author SERPRO | ||
58 | -// * @see DefaultTransaction | ||
59 | -// */ | ||
60 | -//@RunWith(PowerMockRunner.class) | ||
61 | -//@PrepareForTest(CoreBundle.class) | ||
62 | -//public class DefaultTransactionTest { | ||
63 | -// | ||
64 | -// private DefaultTransaction tx; | ||
65 | -// | ||
66 | -// @Before | ||
67 | -// public void setUp() throws Exception { | ||
68 | -// tx = new DefaultTransaction(); | ||
69 | -// | ||
70 | -// mockStatic(CoreBundle.class); | ||
71 | -// | ||
72 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | ||
73 | -// expect(CoreBundle.get()).andReturn(bundle); | ||
74 | -// | ||
75 | -// replay(CoreBundle.class); | ||
76 | -// } | ||
77 | -// | ||
78 | -// @After | ||
79 | -// public void tearDown() { | ||
80 | -// tx = null; | ||
81 | -// } | ||
82 | -// | ||
83 | -// @Test | ||
84 | -// public void testBegin() { | ||
85 | -// try { | ||
86 | -// tx.begin(); | ||
87 | -// } catch (Exception e) { | ||
88 | -// assertTrue(e instanceof DemoiselleException); | ||
89 | -// } | ||
90 | -// } | ||
91 | -// | ||
92 | -// @Test | ||
93 | -// public void testCommit() { | ||
94 | -// try { | ||
95 | -// tx.commit(); | ||
96 | -// } catch (Exception e) { | ||
97 | -// assertTrue(e instanceof DemoiselleException); | ||
98 | -// } | ||
99 | -// } | ||
100 | -// | ||
101 | -// @Test | ||
102 | -// public void testIsActive() { | ||
103 | -// try { | ||
104 | -// tx.isActive(); | ||
105 | -// } catch (Exception e) { | ||
106 | -// assertTrue(e instanceof DemoiselleException); | ||
107 | -// } | ||
108 | -// } | ||
109 | -// | ||
110 | -// @Test | ||
111 | -// public void testIsMarkedRollback() { | ||
112 | -// try { | ||
113 | -// tx.isMarkedRollback(); | ||
114 | -// } catch (Exception e) { | ||
115 | -// assertTrue(e instanceof DemoiselleException); | ||
116 | -// } | ||
117 | -// } | ||
118 | -// | ||
119 | -// @Test | ||
120 | -// public void testRollback() { | ||
121 | -// try { | ||
122 | -// tx.rollback(); | ||
123 | -// } catch (Exception e) { | ||
124 | -// assertTrue(e instanceof DemoiselleException); | ||
125 | -// } | ||
126 | -// } | ||
127 | -// | ||
128 | -// @Test | ||
129 | -// public void testSetRollbackOnly() { | ||
130 | -// try { | ||
131 | -// tx.setRollbackOnly(); | ||
132 | -// } catch (Exception e) { | ||
133 | -// assertTrue(e instanceof DemoiselleException); | ||
134 | -// } | ||
135 | -// } | ||
136 | -//} | 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 br.gov.frameworkdemoiselle.internal.implementation; | ||
38 | + | ||
39 | +import static org.easymock.EasyMock.expect; | ||
40 | +import static org.junit.Assert.assertTrue; | ||
41 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
42 | +import static org.powermock.api.easymock.PowerMock.replay; | ||
43 | + | ||
44 | +import java.util.Locale; | ||
45 | + | ||
46 | +import org.junit.After; | ||
47 | +import org.junit.Before; | ||
48 | +import org.junit.Test; | ||
49 | +import org.junit.runner.RunWith; | ||
50 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
51 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
52 | + | ||
53 | +import br.gov.frameworkdemoiselle.DemoiselleException; | ||
54 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
55 | +import br.gov.frameworkdemoiselle.util.ResourceBundle; | ||
56 | + | ||
57 | +/** | ||
58 | + * @author SERPRO | ||
59 | + * @see DefaultTransaction | ||
60 | + */ | ||
61 | +@RunWith(PowerMockRunner.class) | ||
62 | +@PrepareForTest(Beans.class) | ||
63 | +public class DefaultTransactionTest { | ||
64 | + | ||
65 | + private DefaultTransaction tx; | ||
66 | + | ||
67 | + @Before | ||
68 | + public void setUp() throws Exception { | ||
69 | + tx = new DefaultTransaction(); | ||
70 | + | ||
71 | + mockStatic(Beans.class); | ||
72 | + | ||
73 | + expect(Beans.getReference(Locale.class)).andReturn(Locale.getDefault()); | ||
74 | + | ||
75 | + replay(Beans.class); | ||
76 | + } | ||
77 | + | ||
78 | + @After | ||
79 | + public void tearDown() { | ||
80 | + tx = null; | ||
81 | + } | ||
82 | + | ||
83 | + @Test(expected=DemoiselleException.class) | ||
84 | + public void testBegin() { | ||
85 | + tx.begin(); | ||
86 | + } | ||
87 | + | ||
88 | + @Test(expected=DemoiselleException.class) | ||
89 | + public void testCommit() { | ||
90 | + tx.commit(); | ||
91 | + } | ||
92 | + | ||
93 | + @Test(expected=DemoiselleException.class) | ||
94 | + public void testIsActive() { | ||
95 | + tx.isActive(); | ||
96 | + } | ||
97 | + | ||
98 | + @Test(expected=DemoiselleException.class) | ||
99 | + public void testIsMarkedRollback() { | ||
100 | + tx.isMarkedRollback(); | ||
101 | + } | ||
102 | + | ||
103 | + @Test(expected=DemoiselleException.class) | ||
104 | + public void testRollback() { | ||
105 | + tx.rollback(); | ||
106 | + } | ||
107 | + | ||
108 | + @Test(expected=DemoiselleException.class) | ||
109 | + public void testSetRollbackOnly() { | ||
110 | + tx.setRollbackOnly(); | ||
111 | + } | ||
112 | +} |