Commit 5c9a7ac764000ff972291c88d930a813c5c494bd
1 parent
96785b5d
Exists in
master
Aumento da cobertura de testes na classe PaginationContextImpl.
Showing
1 changed file
with
25 additions
and
2 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/PaginationContextImplTest.java
@@ -36,34 +36,40 @@ | @@ -36,34 +36,40 @@ | ||
36 | */ | 36 | */ |
37 | package br.gov.frameworkdemoiselle.internal.implementation; | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
38 | 38 | ||
39 | +import static org.easymock.EasyMock.expect; | ||
39 | import static org.junit.Assert.assertEquals; | 40 | import static org.junit.Assert.assertEquals; |
40 | import static org.junit.Assert.assertNotNull; | 41 | import static org.junit.Assert.assertNotNull; |
41 | import static org.junit.Assert.assertNull; | 42 | import static org.junit.Assert.assertNull; |
43 | +import static org.powermock.api.easymock.PowerMock.mockStatic; | ||
44 | +import static org.powermock.api.easymock.PowerMock.replayAll; | ||
42 | 45 | ||
43 | import java.util.HashMap; | 46 | import java.util.HashMap; |
44 | import java.util.Map; | 47 | import java.util.Map; |
45 | 48 | ||
46 | import org.easymock.EasyMock; | 49 | import org.easymock.EasyMock; |
47 | import org.junit.After; | 50 | import org.junit.After; |
48 | -import org.junit.Before; | ||
49 | import org.junit.Test; | 51 | import org.junit.Test; |
50 | import org.junit.runner.RunWith; | 52 | import org.junit.runner.RunWith; |
51 | import org.powermock.api.easymock.PowerMock; | 53 | import org.powermock.api.easymock.PowerMock; |
54 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
52 | import org.powermock.modules.junit4.PowerMockRunner; | 55 | import org.powermock.modules.junit4.PowerMockRunner; |
53 | import org.powermock.reflect.Whitebox; | 56 | import org.powermock.reflect.Whitebox; |
54 | 57 | ||
55 | import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; | 58 | import br.gov.frameworkdemoiselle.internal.configuration.PaginationConfig; |
56 | import br.gov.frameworkdemoiselle.pagination.Pagination; | 59 | import br.gov.frameworkdemoiselle.pagination.Pagination; |
57 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; | 60 | import br.gov.frameworkdemoiselle.pagination.PaginationContext; |
61 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
58 | 62 | ||
59 | @RunWith(PowerMockRunner.class) | 63 | @RunWith(PowerMockRunner.class) |
64 | +@PrepareForTest(Beans.class) | ||
60 | public class PaginationContextImplTest { | 65 | public class PaginationContextImplTest { |
61 | 66 | ||
62 | private PaginationContext context; | 67 | private PaginationContext context; |
63 | 68 | ||
69 | + private PaginationConfig config = new PaginationConfig(); | ||
70 | + | ||
64 | private Pagination pagination; | 71 | private Pagination pagination; |
65 | 72 | ||
66 | - @Before | ||
67 | public void setUp() { | 73 | public void setUp() { |
68 | context = new PaginationContextImpl(); | 74 | context = new PaginationContextImpl(); |
69 | 75 | ||
@@ -87,21 +93,38 @@ public class PaginationContextImplTest { | @@ -87,21 +93,38 @@ public class PaginationContextImplTest { | ||
87 | 93 | ||
88 | return map; | 94 | return map; |
89 | } | 95 | } |
96 | + | ||
97 | + @Test | ||
98 | + public void testNullPaginationConfig() { | ||
99 | + context = new PaginationContextImpl(); | ||
100 | + | ||
101 | + mockStatic(Beans.class); | ||
102 | + expect(Beans.getReference(PaginationConfig.class)).andReturn(config).anyTimes(); | ||
103 | + replayAll(Beans.class); | ||
104 | + | ||
105 | + assertNotNull(context.getPagination(Object.class, true)); | ||
106 | + } | ||
90 | 107 | ||
91 | @Test | 108 | @Test |
92 | public void testGetPaginationWithoutCreateParameter() { | 109 | public void testGetPaginationWithoutCreateParameter() { |
110 | + setUp(); | ||
111 | + | ||
93 | assertEquals(pagination, context.getPagination(getClass())); | 112 | assertEquals(pagination, context.getPagination(getClass())); |
94 | assertNull(context.getPagination(Object.class)); | 113 | assertNull(context.getPagination(Object.class)); |
95 | } | 114 | } |
96 | 115 | ||
97 | @Test | 116 | @Test |
98 | public void testGetPaginationWithCreateParameterTrueValued() { | 117 | public void testGetPaginationWithCreateParameterTrueValued() { |
118 | + setUp(); | ||
119 | + | ||
99 | assertEquals(pagination, context.getPagination(getClass(), true)); | 120 | assertEquals(pagination, context.getPagination(getClass(), true)); |
100 | assertNotNull(context.getPagination(Object.class, true)); | 121 | assertNotNull(context.getPagination(Object.class, true)); |
101 | } | 122 | } |
102 | 123 | ||
103 | @Test | 124 | @Test |
104 | public void testGetPaginationWithCreateParameterFalseValued() { | 125 | public void testGetPaginationWithCreateParameterFalseValued() { |
126 | + setUp(); | ||
127 | + | ||
105 | assertEquals(pagination, context.getPagination(getClass(), false)); | 128 | assertEquals(pagination, context.getPagination(getClass(), false)); |
106 | assertNull(context.getPagination(Object.class, false)); | 129 | assertNull(context.getPagination(Object.class, false)); |
107 | } | 130 | } |