22
22
23
23
import static org .junit .jupiter .api .Assertions .assertEquals ;
24
24
import static org .junit .jupiter .api .Assertions .assertThrows ;
25
- import static org .lfenergy .compas .scl .validator .exception .SclValidatorErrorCode .NO_URI_PASSED ;
25
+ import static org .lfenergy .compas .scl .validator .exception .SclValidatorErrorCode .* ;
26
26
import static org .mockito .Mockito .*;
27
27
28
28
@ ExtendWith (MockitoExtension .class )
@@ -46,6 +46,38 @@ void setup() throws IOException {
46
46
.orElseThrow ();
47
47
}
48
48
49
+ @ Test
50
+ void constructor_WhenCalledWithUnCreatableDirectory_ThenExceptionThrown () {
51
+ var unCreatablePath = Path .of ("/some-directory" );
52
+ if (isWindows ()) {
53
+ unCreatablePath = Path .of ("C:/Windows/some-directory" );
54
+ }
55
+
56
+ var directoryPath = unCreatablePath ;
57
+ var exception = assertThrows (SclValidatorException .class ,
58
+ () -> new OclFileLoader (directoryPath , List .of ()));
59
+
60
+ assertEquals (CREATE_OCL_TEMP_DIR_FAILED , exception .getErrorCode ());
61
+ }
62
+
63
+ @ Test
64
+ void constructor_WhenCalledWithUnCreatableTempFile_ThenExceptionThrown () {
65
+ var unWritablePath = Path .of ("/" );
66
+ if (isWindows ()) {
67
+ unWritablePath = Path .of ("C:/Windows" );
68
+ }
69
+
70
+ var directoryPath = unWritablePath ;
71
+ var exception = assertThrows (SclValidatorException .class ,
72
+ () -> new OclFileLoader (directoryPath , List .of ()));
73
+
74
+ assertEquals (CREATE_OCL_TEMP_FILES_FAILED , exception .getErrorCode ());
75
+ }
76
+
77
+ private boolean isWindows () {
78
+ return System .getProperty ("os.name" ).contains ("win" );
79
+ }
80
+
49
81
@ Test
50
82
void loadOCLDocuments_WhenCalled_ThenFilesFromListAreLoaded () throws IOException {
51
83
loader .loadOCLDocuments ();
0 commit comments