3
3
import net .neoforged .moddevgradle .AbstractProjectBuilderTest ;
4
4
import net .neoforged .moddevgradle .dsl .NeoForgeExtension ;
5
5
import net .neoforged .moddevgradle .internal .utils .ExtensionUtils ;
6
+ import net .neoforged .moddevgradle .internal .utils .VersionCapabilities ;
6
7
import org .gradle .api .InvalidUserCodeException ;
7
- import org .gradle .api .Project ;
8
8
import org .gradle .api .Task ;
9
9
import org .gradle .api .plugins .JavaPluginExtension ;
10
10
import org .gradle .api .tasks .SourceSet ;
11
11
import org .gradle .jvm .toolchain .JavaLanguageVersion ;
12
12
import org .gradle .testfixtures .ProjectBuilder ;
13
+ import org .junit .jupiter .api .Nested ;
13
14
import org .junit .jupiter .api .Test ;
14
15
15
16
import java .util .Set ;
16
17
17
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
18
20
import static org .junit .jupiter .api .Assertions .assertThrows ;
19
21
20
22
public class ModDevPluginTest extends AbstractProjectBuilderTest {
@@ -39,32 +41,15 @@ public ModDevPluginTest() {
39
41
40
42
@ Test
41
43
void testModdingCannotBeEnabledTwice () {
42
- extension .setVersion ("1. 2.3" );
43
- var e = assertThrows (InvalidUserCodeException .class , () -> extension .setVersion ("1. 2.3" ));
44
+ extension .setVersion ("2.3.0 " );
45
+ var e = assertThrows (InvalidUserCodeException .class , () -> extension .setVersion ("2.3.0 " ));
44
46
assertThat (e ).hasMessage ("You cannot enable modding in the same project twice." );
45
47
}
46
48
47
- @ Test
48
- void testEnableVanillaOnlyMode () {
49
- extension .setNeoFormVersion ("1.2.3" );
50
-
51
- assertThatDependencies (mainSourceSet .getCompileClasspathConfigurationName ())
52
- .containsOnly (
53
- "build/moddev/artifacts/vanilla-1.2.3.jar" ,
54
- "net.neoforged:neoform:1.2.3[net.neoforged:neoform-dependencies]"
55
- );
56
- assertThatDependencies (mainSourceSet .getRuntimeClasspathConfigurationName ())
57
- .containsOnly (
58
- "build/moddev/artifacts/vanilla-1.2.3.jar" ,
59
- "build/moddev/artifacts/vanilla-1.2.3-client-extra-aka-minecraft-resources.jar" ,
60
- "net.neoforged:neoform:1.2.3[net.neoforged:neoform-dependencies]"
61
- );
62
- }
63
-
64
49
@ Test
65
50
void testEnableForTestSourceSetOnly () {
66
51
extension .enable (settings -> {
67
- settings .setVersion ("1. 2.3" );
52
+ settings .setVersion ("2.3.0 " );
68
53
settings .setEnabledSourceSets (Set .of (testSourceSet ));
69
54
});
70
55
@@ -73,25 +58,117 @@ void testEnableForTestSourceSetOnly() {
73
58
assertThatDependencies (mainSourceSet .getRuntimeClasspathConfigurationName ()).isEmpty ();
74
59
75
60
// While the test classpath should have modding dependencies
76
- assertContainsModdingCompileDependencies ("1. 2.3" , testSourceSet .getCompileClasspathConfigurationName ());
77
- assertContainsModdingRuntimeDependencies ("1. 2.3" , testSourceSet .getRuntimeClasspathConfigurationName ());
61
+ assertContainsModdingCompileDependencies ("2.3.0 " , testSourceSet .getCompileClasspathConfigurationName ());
62
+ assertContainsModdingRuntimeDependencies ("2.3.0 " , testSourceSet .getRuntimeClasspathConfigurationName ());
78
63
}
79
64
80
65
@ Test
81
66
void testAddModdingDependenciesTo () {
82
- extension .setVersion ("1. 2.3" );
67
+ extension .setVersion ("2.3.0 " );
83
68
84
69
// Initially, only the main source set should have the dependencies
85
- assertContainsModdingCompileDependencies ("1. 2.3" , mainSourceSet .getCompileClasspathConfigurationName ());
86
- assertContainsModdingRuntimeDependencies ("1. 2.3" , mainSourceSet .getRuntimeClasspathConfigurationName ());
70
+ assertContainsModdingCompileDependencies ("2.3.0 " , mainSourceSet .getCompileClasspathConfigurationName ());
71
+ assertContainsModdingRuntimeDependencies ("2.3.0 " , mainSourceSet .getRuntimeClasspathConfigurationName ());
87
72
assertThatDependencies (testSourceSet .getCompileClasspathConfigurationName ()).isEmpty ();
88
73
assertThatDependencies (testSourceSet .getRuntimeClasspathConfigurationName ()).isEmpty ();
89
74
90
75
// Now add it to the test source set too
91
76
extension .addModdingDependenciesTo (testSourceSet );
92
77
93
- assertContainsModdingCompileDependencies ("1.2.3" , testSourceSet .getCompileClasspathConfigurationName ());
94
- assertContainsModdingRuntimeDependencies ("1.2.3" , testSourceSet .getRuntimeClasspathConfigurationName ());
78
+ assertContainsModdingCompileDependencies ("2.3.0" , testSourceSet .getCompileClasspathConfigurationName ());
79
+ assertContainsModdingRuntimeDependencies ("2.3.0" , testSourceSet .getRuntimeClasspathConfigurationName ());
80
+ }
81
+
82
+ @ Test
83
+ void testGetVersion () {
84
+ extension .setVersion ("2.3.0" );
85
+ assertEquals ("2.3.0" , extension .getVersion ());
86
+ }
87
+
88
+ @ Test
89
+ void testGetVersionCapabilities () {
90
+ extension .setVersion ("2.3.0" );
91
+ assertEquals (VersionCapabilities .ofMinecraftVersion ("1.2.3" ), extension .getVersionCapabilities ());
92
+ assertEquals ("1.2.3" , extension .getVersionCapabilities ().minecraftVersion ());
93
+ }
94
+
95
+ @ Test
96
+ void testGetMinecraftVersion () {
97
+ extension .setVersion ("2.3.0-suffixstuff" );
98
+ assertEquals ("1.2.3" , extension .getMinecraftVersion ());
99
+ }
100
+
101
+ @ Nested
102
+ class VanillaOnlyMode {
103
+ final static String VERSION = "1.21.4-20240101.235959" ;
104
+
105
+ @ Test
106
+ void testEnable () {
107
+ extension .setNeoFormVersion (VERSION );
108
+
109
+ assertThatDependencies (mainSourceSet .getCompileClasspathConfigurationName ())
110
+ .containsOnly (
111
+ "build/moddev/artifacts/vanilla-" + VERSION + ".jar" ,
112
+ "net.neoforged:neoform:" + VERSION + "[net.neoforged:neoform-dependencies]"
113
+ );
114
+ assertThatDependencies (mainSourceSet .getRuntimeClasspathConfigurationName ())
115
+ .containsOnly (
116
+ "build/moddev/artifacts/vanilla-" + VERSION + ".jar" ,
117
+ "build/moddev/artifacts/vanilla-" + VERSION + "-client-extra-aka-minecraft-resources.jar" ,
118
+ "net.neoforged:neoform:" + VERSION + "[net.neoforged:neoform-dependencies]"
119
+ );
120
+ }
121
+
122
+ @ Test
123
+ void testGetVersion () {
124
+ extension .setNeoFormVersion (VERSION );
125
+ assertEquals (VersionCapabilities .ofNeoFormVersion (VERSION ), extension .getVersionCapabilities ());
126
+ }
127
+
128
+ @ Test
129
+ void testGetMinecraftVersion () {
130
+ extension .setNeoFormVersion (VERSION );
131
+ assertEquals ("1.21.4" , extension .getMinecraftVersion ());
132
+ }
133
+
134
+ @ Test
135
+ void testGetVersionCapabilities () {
136
+ extension .setNeoFormVersion (VERSION );
137
+ assertEquals (VersionCapabilities .ofNeoFormVersion (VERSION ), extension .getVersionCapabilities ());
138
+ }
139
+
140
+ @ Test
141
+ void testGetVersionCapabilitiesForUnknownVersion () {
142
+ extension .setNeoFormVersion ("1.99.1-20990101.235959" );
143
+ // Should use latest features, but with the specified Minecraft version
144
+ assertEquals (
145
+ VersionCapabilities .latest ().withMinecraftVersion ("1.99.1" ),
146
+ extension .getVersionCapabilities ()
147
+ );
148
+ }
149
+ }
150
+
151
+ @ Nested
152
+ class CannotCallWhenModdingIsNotEnabled {
153
+ static String expectedMessage = "Mod development has not been enabled yet for project root project 'test'" ;
154
+
155
+ @ Test
156
+ void testGettingMinecraftVersionThrows () {
157
+ var e = assertThrows (InvalidUserCodeException .class , extension ::getVersionCapabilities );
158
+ assertThat (e ).hasMessage (expectedMessage );
159
+ }
160
+
161
+ @ Test
162
+ void testGettingVersionCapabilitiesThrows () {
163
+ var e = assertThrows (InvalidUserCodeException .class , extension ::getVersion );
164
+ assertThat (e ).hasMessage (expectedMessage );
165
+ }
166
+
167
+ @ Test
168
+ void testAddModdingDependenciesToThrows () {
169
+ var e = assertThrows (InvalidUserCodeException .class , () -> extension .addModdingDependenciesTo (mainSourceSet ));
170
+ assertThat (e ).hasMessage (expectedMessage );
171
+ }
95
172
}
96
173
97
174
private void assertContainsModdingCompileDependencies (String version , String configurationName ) {
0 commit comments