1
1
package org .web3j .gradle .plugin ;
2
2
3
+ import java .io .File ;
4
+ import java .io .IOException ;
5
+ import java .net .URL ;
6
+ import java .nio .file .Files ;
7
+
3
8
import org .gradle .testkit .runner .BuildResult ;
4
9
import org .gradle .testkit .runner .GradleRunner ;
5
10
import org .junit .Before ;
6
11
import org .junit .Rule ;
7
12
import org .junit .Test ;
8
13
import org .junit .rules .TemporaryFolder ;
9
14
10
- import java .io .File ;
11
- import java .io .IOException ;
12
- import java .net .URL ;
13
- import java .nio .file .Files ;
14
-
15
15
import static org .gradle .testkit .runner .TaskOutcome .SUCCESS ;
16
16
import static org .gradle .testkit .runner .TaskOutcome .UP_TO_DATE ;
17
- import static org .junit .Assert .*;
17
+ import static org .junit .Assert .assertEquals ;
18
+ import static org .junit .Assert .assertFalse ;
19
+ import static org .junit .Assert .assertNotNull ;
20
+ import static org .junit .Assert .assertTrue ;
18
21
19
22
public class Web3jPluginTest {
20
23
@@ -35,7 +38,7 @@ public void setup() throws IOException {
35
38
}
36
39
37
40
@ Test
38
- public void generateContractWrappers () throws IOException {
41
+ public void generateContractWrappersExcluding () throws IOException {
39
42
final String buildFileContent = "plugins {\n " +
40
43
" id 'org.web3j'\n " +
41
44
"}\n " +
@@ -89,4 +92,59 @@ public void generateContractWrappers() throws IOException {
89
92
assertEquals (UP_TO_DATE , upToDate .task (":generateContractWrappers" ).getOutcome ());
90
93
}
91
94
95
+ @ Test
96
+ public void generateContractWrappersIncluding () throws IOException {
97
+ final String buildFileContent = "plugins {\n " +
98
+ " id 'org.web3j'\n " +
99
+ "}\n " +
100
+ "web3j {\n " +
101
+ " generatedPackageName = 'org.web3j.test'\n " +
102
+ " includedContracts = ['StandardToken']\n " +
103
+ "}\n " +
104
+ "sourceSets {\n " +
105
+ " main {\n " +
106
+ " solidity {\n " +
107
+ " srcDir {" +
108
+ " '" + sourceDir .getAbsolutePath () + "'\n " +
109
+ " }\n " +
110
+ " }\n " +
111
+ " }\n " +
112
+ "}\n " +
113
+ "repositories {\n " +
114
+ " mavenCentral()\n " +
115
+ "}\n " +
116
+ "dependencies {\n " +
117
+ " implementation \" org.web3j:core:4.1.1\" \n " +
118
+ "}\n " ;
119
+
120
+ Files .write (buildFile .toPath (), buildFileContent .getBytes ());
121
+
122
+ final GradleRunner gradleRunner = GradleRunner .create ()
123
+ .withProjectDir (testProjectDir .getRoot ())
124
+ .withArguments ("build" )
125
+ .withPluginClasspath ()
126
+ .forwardOutput ();
127
+
128
+ final BuildResult success = gradleRunner .build ();
129
+ assertNotNull (success .task (":generateContractWrappers" ));
130
+ assertEquals (SUCCESS , success .task (":generateContractWrappers" ).getOutcome ());
131
+
132
+ final File web3jContractsDir = new File (testProjectDir .getRoot (),
133
+ "build/generated/source/web3j/main/java" );
134
+
135
+ final File generatedContract = new File (web3jContractsDir ,
136
+ "org/web3j/test/StandardToken.java" );
137
+
138
+ assertTrue (generatedContract .exists ());
139
+
140
+ final File excludedContract = new File (web3jContractsDir ,
141
+ "org/web3j/test/Token.java" );
142
+
143
+ assertFalse (excludedContract .exists ());
144
+
145
+ final BuildResult upToDate = gradleRunner .build ();
146
+ assertNotNull (upToDate .task (":generateContractWrappers" ));
147
+ assertEquals (UP_TO_DATE , upToDate .task (":generateContractWrappers" ).getOutcome ());
148
+ }
149
+
92
150
}
0 commit comments