1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.store

File ProvidingTransactionRunnableTest.java

 

Code metrics

0
24
11
9
148
102
11
0.46
2.18
1.22
1

Classes

Class Line # Actions
ProvidingTransactionRunnableTest 31 12 0% 2 6
0.571428657.1%
ProvidingTransactionRunnableTest.DBTransaction 60 0 - 0 0
-1.0 -
ProvidingTransactionRunnableTest.MyDBTransaction 65 1 0% 1 0
1.0100%
ProvidingTransactionRunnableTest.MyInterfaceWithDataA1 73 0 - 0 0
-1.0 -
ProvidingTransactionRunnableTest.ImplementationWithDataA1 78 4 0% 3 0
1.0100%
ProvidingTransactionRunnableTest.DBStartableTransactionRunnable 101 1 0% 1 0
1.0100%
ProvidingTransactionRunnableTest.TR1 110 3 0% 2 0
1.0100%
ProvidingTransactionRunnableTest.TR2 129 1 0% 1 0
1.0100%
ProvidingTransactionRunnableTest.TR3 138 2 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.store;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24   
25    /**
26    * Tests for ProvidingTransactionRunnable.
27    *
28    * @version $Id: 3bfeebd6c01db1cf4ce17d7dee9c074ec4b6d189 $
29    * @since 3.0M2
30    */
 
31    public class ProvidingTransactionRunnableTest
32    {
33    private static final String DB_CONNECTION = "Hello, I'm a database connection!";
34   
35    private static final String DATA_A1 = "hello world";
36   
 
37  1 toggle @Test
38    public void dataSharingTest() throws Exception
39    {
40  1 DBStartableTransactionRunnable run = new DBStartableTransactionRunnable();
41  1 ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1> tr1 = new TR1();
42  1 tr1.runIn(run);
43  1 TransactionRunnable<DBTransaction> tr2 = new TR2();
44  1 TransactionRunnable<MyInterfaceWithDataA1> tr2WithNewCapabilities = tr2.runIn(tr1.asProvider());
45   
46  1 new TR3().runIn(tr2WithNewCapabilities);
47    // This should fail at compile time: new TR3().runIn(tr2);
48  1 run.start();
49    }
50   
 
51  0 toggle public void providingTest() throws Exception
52    {
53  0 DBStartableTransactionRunnable run = new DBStartableTransactionRunnable();
54  0 ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1> tr1 = new TR1();
55  0 tr1.runIn(run);
56  0 new TR3().runIn(tr1.asProvider());
57  0 run.start();
58    }
59   
 
60    public static interface DBTransaction
61    {
62    String getConnection();
63    }
64   
 
65    public static class MyDBTransaction implements DBTransaction
66    {
 
67  3 toggle public String getConnection()
68    {
69  3 return DB_CONNECTION;
70    }
71    }
72   
 
73    public static interface MyInterfaceWithDataA1 extends DBTransaction
74    {
75    String getDataA1();
76    }
77   
 
78    public static class ImplementationWithDataA1 implements MyInterfaceWithDataA1
79    {
80    private final DBTransaction DBTrans;
81   
82    private final String dataA1;
83   
 
84  3 toggle public ImplementationWithDataA1(final DBTransaction transact, final String dataA1)
85    {
86  3 this.DBTrans = transact;
87  3 this.dataA1 = dataA1;
88    }
89   
 
90  1 toggle public String getDataA1()
91    {
92  1 return this.dataA1;
93    }
94   
 
95  2 toggle public String getConnection()
96    {
97  2 return this.DBTrans.getConnection();
98    }
99    }
100   
 
101    public static class DBStartableTransactionRunnable extends StartableTransactionRunnable<DBTransaction>
102    {
 
103  4 toggle @Override
104    protected DBTransaction getProvidedContext()
105    {
106  4 return new MyDBTransaction();
107    }
108    }
109   
 
110    public static class TR1 extends ProvidingTransactionRunnable<DBTransaction, MyInterfaceWithDataA1>
111    {
112    private String dataA1;
113   
 
114  1 toggle @Override
115    protected void onRun()
116    {
117  1 Assert.assertEquals("DB Connection was not correct in TR1",
118    DB_CONNECTION, this.getContext().getConnection());
119  1 this.dataA1 = DATA_A1;
120    }
121   
 
122  3 toggle @Override
123    protected MyInterfaceWithDataA1 getProvidedContext()
124    {
125  3 return new ImplementationWithDataA1(this.getContext(), this.dataA1);
126    }
127    }
128   
 
129    public class TR2 extends TransactionRunnable<DBTransaction>
130    {
 
131  1 toggle protected void onRun()
132    {
133  1 Assert.assertEquals("DB Connection was not correct in TR2",
134    DB_CONNECTION, this.getContext().getConnection());
135    }
136    }
137   
 
138    public class TR3 extends TransactionRunnable<MyInterfaceWithDataA1>
139    {
 
140  1 toggle protected void onRun()
141    {
142  1 Assert.assertEquals("Data A1 was not correct in TR3",
143    DATA_A1, this.getContext().getDataA1());
144  1 Assert.assertEquals("DB Connection was not correct in TR3",
145    DB_CONNECTION, this.getContext().getConnection());
146    }
147    }
148    }