KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > db4ounit > extensions > tests > AllTests


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package db4ounit.extensions.tests;
22
23 import db4ounit.*;
24 import db4ounit.extensions.*;
25 import db4ounit.extensions.fixtures.*;
26 import db4ounit.tests.*;
27
28 public class AllTests implements TestCase {
29     private final class ExcludingInMemoryFixture extends Db4oInMemory {
30         public ExcludingInMemoryFixture(ConfigurationSource source) {
31             super(source);
32         }
33
34         public boolean accept(Class JavaDoc clazz) {
35             return !OptOutFromTestFixture.class.isAssignableFrom(clazz);
36         }
37     }
38
39     public static void main(String JavaDoc[] args) {
40         new TestRunner(AllTests.class).run();
41     }
42     
43     public void testSingleTestWithDifferentFixtures() {
44         ConfigurationSource configSource=new IndependentConfigurationSource();
45         assertSimpleDb4o(new Db4oInMemory(configSource));
46         assertSimpleDb4o(new Db4oSolo(configSource));
47     }
48     
49     public void testMultipleTestsSingleFixture() {
50         MultipleDb4oTestCase.resetConfigureCalls();
51         FrameworkTestCase.runTestAndExpect(new Db4oTestSuiteBuilder(new Db4oInMemory(new IndependentConfigurationSource()), MultipleDb4oTestCase.class).build(), 2, false);
52         Assert.areEqual(2,MultipleDb4oTestCase.configureCalls());
53     }
54
55     public void testSelectiveFixture() {
56         Db4oFixture fixture=new ExcludingInMemoryFixture(new IndependentConfigurationSource());
57         TestSuite suite = new Db4oTestSuiteBuilder(fixture, new Class JavaDoc[]{AcceptedTestCase.class,NotAcceptedTestCase.class}).build();
58         Assert.areEqual(1,suite.getTests().length);
59         FrameworkTestCase.runTestAndExpect(suite,0);
60     }
61     
62     private void assertSimpleDb4o(Db4oFixture fixture) {
63         TestSuite suite = new Db4oTestSuiteBuilder(fixture, SimpleDb4oTestCase.class).build();
64         SimpleDb4oTestCase subject = getTestSubject(suite);
65         subject.expectedFixture(fixture);
66         FrameworkTestCase.runTestAndExpect(suite, 0);
67         Assert.isTrue(subject.everythingCalled());
68     }
69
70     private SimpleDb4oTestCase getTestSubject(TestSuite suite) {
71         return ((SimpleDb4oTestCase)((TestMethod)suite.getTests()[0]).getSubject());
72     }
73 }
74
Popular Tags