Commit ec946f2fcd3f1ed2069f59625118a583682627a4
1 parent
31a0eb70
Exists in
master
Adição de testes unitários para classe TransactionContextImpl.
Showing
1 changed file
with
124 additions
and
0 deletions
Show diff stats
impl/core/src/test/java/br/gov/frameworkdemoiselle/internal/implementation/TransactionContextImplTest.java
0 → 100644
| @@ -0,0 +1,124 @@ | @@ -0,0 +1,124 @@ | ||
| 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.powermock.api.easymock.PowerMock.mockStatic; | ||
| 41 | +import static org.powermock.api.easymock.PowerMock.replayAll; | ||
| 42 | + | ||
| 43 | +import java.util.ArrayList; | ||
| 44 | +import java.util.List; | ||
| 45 | + | ||
| 46 | +import junit.framework.Assert; | ||
| 47 | + | ||
| 48 | +import org.easymock.EasyMock; | ||
| 49 | +import org.junit.Test; | ||
| 50 | +import org.junit.runner.RunWith; | ||
| 51 | +import org.powermock.api.easymock.PowerMock; | ||
| 52 | +import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| 53 | +import org.powermock.modules.junit4.PowerMockRunner; | ||
| 54 | +import org.powermock.reflect.Whitebox; | ||
| 55 | + | ||
| 56 | +import br.gov.frameworkdemoiselle.internal.bootstrap.TransactionBootstrap; | ||
| 57 | +import br.gov.frameworkdemoiselle.internal.configuration.TransactionConfig; | ||
| 58 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | ||
| 59 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | ||
| 60 | +import br.gov.frameworkdemoiselle.util.Beans; | ||
| 61 | + | ||
| 62 | +@RunWith(PowerMockRunner.class) | ||
| 63 | +@PrepareForTest({Beans.class,StrategySelector.class}) | ||
| 64 | +public class TransactionContextImplTest { | ||
| 65 | + | ||
| 66 | + private TransactionContext context; | ||
| 67 | + private Transaction transaction; | ||
| 68 | + | ||
| 69 | + class TransactionImpl implements Transaction{ | ||
| 70 | + | ||
| 71 | + private static final long serialVersionUID = 1L; | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public boolean isActive() { | ||
| 75 | + return false; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public boolean isMarkedRollback() { | ||
| 80 | + return false; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public void begin() { | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + public void commit() { | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + @Override | ||
| 92 | + public void rollback() { | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public void setRollbackOnly() { | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Test | ||
| 101 | + public void testGetTransactionNull() { | ||
| 102 | + context = new TransactionContextImpl(); | ||
| 103 | + | ||
| 104 | + Class<? extends Transaction> cache = TransactionImpl.class; | ||
| 105 | + | ||
| 106 | + List<Class<? extends Transaction>> cacheList = new ArrayList<Class<? extends Transaction>>(); | ||
| 107 | + cacheList.add(cache); | ||
| 108 | + | ||
| 109 | + TransactionBootstrap bootstrap = PowerMock.createMock(TransactionBootstrap.class); | ||
| 110 | + TransactionConfig config = PowerMock.createMock(TransactionConfig.class); | ||
| 111 | + | ||
| 112 | + mockStatic(Beans.class); | ||
| 113 | + expect(Beans.getReference(TransactionBootstrap.class)).andReturn(bootstrap).anyTimes(); | ||
| 114 | + expect(Beans.getReference(TransactionConfig.class)).andReturn(config); | ||
| 115 | + expect(config.getTransactionClass()).andReturn(null).anyTimes(); | ||
| 116 | + expect(bootstrap.getCache()).andReturn(cacheList); | ||
| 117 | + expect(Beans.getReference(TransactionImpl.class)).andReturn(new TransactionImpl()); | ||
| 118 | + | ||
| 119 | + replayAll(Beans.class); | ||
| 120 | + | ||
| 121 | + transaction = context.getCurrentTransaction(); | ||
| 122 | + Assert.assertNotNull(transaction); | ||
| 123 | + } | ||
| 124 | +} |