@@ -22,58 +22,88 @@ public void testIdValidation() {
22
22
Enigma .builder ().setPlugins (List .of (new IdTestPlugin ())).build ();
23
23
}
24
24
25
+ @ Test
26
+ public void testDuplicateServices () {
27
+ Enigma .builder ().setPlugins (List .of (new DuplicateIdTestPlugin ())).build ();
28
+ }
29
+
30
+ @ Test
31
+ public void testDuplicateFileTypes () {
32
+ Enigma .builder ().setPlugins (List .of (new DuplicateFileTypeTestPlugin ())).build ();
33
+ }
34
+
35
+ private static void registerService (EnigmaPluginContext ctx , String id ) {
36
+ registerService (ctx , id , id );
37
+ }
38
+
39
+ private static void registerService (EnigmaPluginContext ctx , String id , String fileType ) {
40
+ ctx .registerService (ReadWriteService .TYPE , ctx1 -> new ReadWriteService () {
41
+ @ Override
42
+ public void write (EntryTree <EntryMapping > mappings , MappingDelta <EntryMapping > delta , Path path , ProgressListener progress , MappingSaveParameters saveParameters ) {
43
+ }
44
+
45
+ @ Override
46
+ public EntryTree <EntryMapping > read (Path path , ProgressListener progress ) {
47
+ return null ;
48
+ }
49
+
50
+ @ Override
51
+ public FileType getFileType () {
52
+ return new FileType .File (fileType );
53
+ }
54
+
55
+ @ Override
56
+ public boolean supportsReading () {
57
+ return false ;
58
+ }
59
+
60
+ @ Override
61
+ public boolean supportsWriting () {
62
+ return false ;
63
+ }
64
+
65
+ @ Override
66
+ public String getId () {
67
+ return id ;
68
+ }
69
+ });
70
+ }
71
+
72
+ private static class DuplicateFileTypeTestPlugin implements EnigmaPlugin {
73
+ @ Override
74
+ public void init (EnigmaPluginContext ctx ) {
75
+ registerService (ctx , "test:grind" , "gaming" );
76
+ Assertions .assertThrows (IllegalStateException .class , () -> registerService (ctx , "test:slay" , "gaming" ));
77
+ }
78
+ }
79
+
80
+ private static class DuplicateIdTestPlugin implements EnigmaPlugin {
81
+ @ Override
82
+ public void init (EnigmaPluginContext ctx ) {
83
+ registerService (ctx , "grind:ground" );
84
+ Assertions .assertThrows (IllegalStateException .class , () -> registerService (ctx , "grind:ground" ));
85
+ }
86
+ }
87
+
25
88
private static class IdTestPlugin implements EnigmaPlugin {
26
89
@ Override
27
90
public void init (EnigmaPluginContext ctx ) {
28
91
// empty
29
- Assertions .assertThrows (IllegalArgumentException .class , () -> this . registerService (ctx , "" ));
92
+ Assertions .assertThrows (IllegalArgumentException .class , () -> registerService (ctx , "" ));
30
93
// no namespace
31
- Assertions .assertThrows (IllegalArgumentException .class , () -> this . registerService (ctx , "grind" ));
94
+ Assertions .assertThrows (IllegalArgumentException .class , () -> registerService (ctx , "grind" ));
32
95
// slashes in wrong place
33
- Assertions .assertThrows (IllegalArgumentException .class , () -> this . registerService (ctx , "grind/grind:ground" ));
96
+ Assertions .assertThrows (IllegalArgumentException .class , () -> registerService (ctx , "grind/grind:ground" ));
34
97
// uppercase chars
35
- Assertions .assertThrows (IllegalArgumentException .class , () -> this . registerService (ctx , "grind:Ground" ));
98
+ Assertions .assertThrows (IllegalArgumentException .class , () -> registerService (ctx , "grind:Ground" ));
36
99
// invalid chars
37
- Assertions .assertThrows (IllegalArgumentException .class , () -> this . registerService (ctx , "grind:ground!" ));
100
+ Assertions .assertThrows (IllegalArgumentException .class , () -> registerService (ctx , "grind:ground!" ));
38
101
// valid
39
- this .registerService (ctx , "grind:ground" );
40
- this .registerService (ctx , "grind:ground_" );
41
- this .registerService (ctx , "grind:ground_grind/g_rind2" );
42
- this .registerService (ctx , "grind:ground/grind" );
43
- this .registerService (ctx , "grind:ground/grind/grind" );
44
- }
45
-
46
- private void registerService (EnigmaPluginContext ctx , String id ) {
47
- ctx .registerService (ReadWriteService .TYPE , ctx1 -> new ReadWriteService () {
48
- @ Override
49
- public void write (EntryTree <EntryMapping > mappings , MappingDelta <EntryMapping > delta , Path path , ProgressListener progress , MappingSaveParameters saveParameters ) {
50
- }
51
-
52
- @ Override
53
- public EntryTree <EntryMapping > read (Path path , ProgressListener progress ) {
54
- return null ;
55
- }
56
-
57
- @ Override
58
- public FileType getFileType () {
59
- return new FileType .File (id );
60
- }
61
-
62
- @ Override
63
- public boolean supportsReading () {
64
- return false ;
65
- }
66
-
67
- @ Override
68
- public boolean supportsWriting () {
69
- return false ;
70
- }
71
-
72
- @ Override
73
- public String getId () {
74
- return id ;
75
- }
76
- });
102
+ registerService (ctx , "grind:ground" );
103
+ registerService (ctx , "grind:ground_" );
104
+ registerService (ctx , "grind:ground_grind/g_rind2" );
105
+ registerService (ctx , "grind:ground/grind" );
106
+ registerService (ctx , "grind:ground/grind/grind" );
77
107
}
78
108
}
79
109
}
0 commit comments