44import static datadog .nativeloader .TestPlatformSpec .LINUX ;
55import static datadog .nativeloader .TestPlatformSpec .UNSUPPORTED_ARCH ;
66import static datadog .nativeloader .TestPlatformSpec .UNSUPPORTED_OS ;
7+
8+
9+ import static org .junit .jupiter .api .Assertions .assertEquals ;
710import static org .junit .jupiter .api .Assertions .assertFalse ;
11+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
12+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
813import static org .junit .jupiter .api .Assertions .assertNull ;
914import static org .junit .jupiter .api .Assertions .assertThrows ;
1015import static org .junit .jupiter .api .Assertions .assertTrue ;
@@ -26,11 +31,7 @@ public void preloaded() throws LibraryLoadException {
2631 assertFalse (loader .isPreloaded ("dne3" ));
2732
2833 try (LibFile lib = loader .resolveDynamic ("dne1" )) {
29- assertTrue (lib .isPreloaded ());
30-
31- assertNull (lib .file );
32- assertNull (lib .getAbsolutePath ());
33- assertFalse (lib .needsCleanup );
34+ assertPreloaded (lib );
3435
3536 // already considered loaded -- so this is a nop
3637 lib .load ();
@@ -75,7 +76,10 @@ public void fromDir() throws LibraryLoadException {
7576
7677 try (LibFile lib = loader .resolveDynamic ("dummy" )) {
7778 // loaded directly from directory, so no clean-up required
78- assertNonTempFile (lib );
79+ assertRegularFile (lib );
80+
81+ // file isn't actually a dynamic library
82+ assertThrows (LibraryLoadException .class , () -> lib .load ());
7983 }
8084 }
8185
@@ -85,7 +89,7 @@ public void fromDirList() throws LibraryLoadException {
8589
8690 try (LibFile lib = loader .resolveDynamic ("dummy" )) {
8791 // loaded directly from directory, so no clean-up required
88- assertNonTempFile (lib );
92+ assertRegularFile (lib );
8993 }
9094 }
9195
@@ -94,12 +98,12 @@ public void fromDir_with_component() throws LibraryLoadException {
9498 NativeLoader loader = NativeLoader .builder ().fromDir ("test-data" ).build ();
9599
96100 try (LibFile lib = loader .resolveDynamic ("comp1" , "dummy" )) {
97- assertNonTempFile (lib );
101+ assertRegularFile (lib );
98102 assertTrue (lib .getAbsolutePath ().contains ("comp1" ));
99103 }
100104
101105 try (LibFile lib = loader .resolveDynamic ("comp2" , "dummy" )) {
102- assertNonTempFile (lib );
106+ assertRegularFile (lib );
103107 assertTrue (lib .getAbsolutePath ().contains ("comp2" ));
104108 }
105109 }
@@ -113,7 +117,7 @@ public void fromDirBackedClassLoader() throws IOException, LibraryLoadException
113117 NativeLoader loader = NativeLoader .builder ().fromClassLoader (classLoader ).build ();
114118 try (LibFile lib = loader .resolveDynamic ("dummy" )) {
115119 // since there's a normal file, no need to copy to a temp file and clean-up
116- assertNonTempFile (lib );
120+ assertRegularFile (lib );
117121 }
118122 }
119123 }
@@ -127,12 +131,12 @@ public void fromDirBackedClassLoader_with_component() throws IOException, Librar
127131 NativeLoader loader = NativeLoader .builder ().fromClassLoader (classLoader ).build ();
128132
129133 try (LibFile lib = loader .resolveDynamic ("comp1" , "dummy" )) {
130- assertNonTempFile (lib );
134+ assertRegularFile (lib );
131135 assertTrue (lib .getAbsolutePath ().contains ("comp1" ));
132136 }
133137
134138 try (LibFile lib = loader .resolveDynamic ("comp2" , "dummy" )) {
135- assertNonTempFile (lib );
139+ assertRegularFile (lib );
136140 assertTrue (lib .getAbsolutePath ().contains ("comp2" ));
137141 }
138142 }
@@ -147,7 +151,7 @@ public void fromDirBackedClassLoader_with_subResource() throws IOException, Libr
147151 NativeLoader loader = NativeLoader .builder ().fromClassLoader (classLoader , "resource" ).build ();
148152 try (LibFile lib = loader .resolveDynamic ("dummy" )) {
149153 // since there's a normal file, no need to copy to a temp file and clean-up
150- assertNonTempFile (lib );
154+ assertRegularFile (lib );
151155 assertTrue (lib .getAbsolutePath ().contains ("resource" ));
152156 }
153157 }
@@ -163,7 +167,7 @@ public void fromDirBackedClassLoader_with_subResource_and_comp()
163167 NativeLoader loader = NativeLoader .builder ().fromClassLoader (classLoader , "resource" ).build ();
164168 try (LibFile lib = loader .resolveDynamic ("comp1" , "dummy" )) {
165169 // since there's a normal file, no need to copy to a temp file and clean-up
166- assertNonTempFile (lib );
170+ assertRegularFile (lib );
167171 assertTrue (lib .getAbsolutePath ().contains ("comp1" ));
168172 assertTrue (lib .getAbsolutePath ().contains ("resource" ));
169173 }
@@ -182,12 +186,27 @@ public void fromJarBackedClassLoader() throws IOException, LibraryLoadException
182186 assertTempFile (lib );
183187 }
184188 }
189+
190+ void assertPreloaded (LibFile lib ) {
191+ assertTrue (lib .isPreloaded ());
192+ assertNull (lib .file );
193+ assertNull (lib .getAbsolutePath ());
194+ assertFalse (lib .needsCleanup );
195+ }
185196
186- void assertNonTempFile (LibFile file ) {
187- assertFalse (file .needsCleanup );
197+ void assertRegularFile (LibFile lib ) {
198+ assertFalse (lib .isPreloaded ());
199+ assertNotNull (lib .file );
200+ assertTrue (lib .file .exists ());
201+ assertEquals (lib .file .getAbsolutePath (), lib .getAbsolutePath ());
202+ assertFalse (lib .needsCleanup );
188203 }
189204
190- void assertTempFile (LibFile file ) {
191- assertTrue (file .needsCleanup );
205+ void assertTempFile (LibFile lib ) {
206+ assertFalse (lib .isPreloaded ());
207+ assertNotNull (lib .file );
208+ assertTrue (lib .file .exists ());
209+ assertEquals (lib .file .getAbsolutePath (), lib .getAbsolutePath ());
210+ assertTrue (lib .needsCleanup );
192211 }
193212}
0 commit comments