22
33import org .junit .jupiter .api .BeforeEach ;
44import org .junit .jupiter .api .Test ;
5- import software .amazon .awssdk .services .s3 .S3Client ;
65import uk .nhs .adaptors .gp2gp .common .storage .StorageConnectorConfiguration ;
7- import static org .junit .jupiter .api .Assertions .assertNull ;
6+ import javax .naming .ConfigurationException ;
7+ import static org .junit .jupiter .api .Assertions .assertEquals ;
8+ import static org .junit .jupiter .api .Assertions .assertThrows ;
89
910class AppInitializerTest {
1011
12+ public static final String EXPECTED_ERROR_MESSAGE = "S3Client cannot be instantiated due to trust store URL misconfiguration" ;
1113 private AppInitializer appInitializer ;
1214 private StorageConnectorConfiguration storageConnectorConfiguration ;
1315
@@ -22,9 +24,9 @@ void getNullWhenTrustStoreUrlDoesNotExists() {
2224 storageConnectorConfiguration .setTrustStoreUrl (null );
2325 appInitializer = new AppInitializer (storageConnectorConfiguration );
2426
25- S3Client s3Client = appInitializer .getS3Client ();
27+ Exception exception = assertThrows ( ConfigurationException . class , () -> appInitializer .getS3Client () );
2628
27- assertNull ( s3Client );
29+ assertEquals ( EXPECTED_ERROR_MESSAGE , exception . getMessage () );
2830 }
2931
3032 @ Test
@@ -33,8 +35,8 @@ void getNullWhenTrustStoreUrlDoesNotStartWithS3Prefix() {
3335 storageConnectorConfiguration .setTrustStoreUrl ("http://localhost" );
3436 appInitializer = new AppInitializer (storageConnectorConfiguration );
3537
36- S3Client s3Client = appInitializer .getS3Client ();
38+ Exception exception = assertThrows ( ConfigurationException . class , () -> appInitializer .getS3Client () );
3739
38- assertNull ( s3Client );
40+ assertEquals ( EXPECTED_ERROR_MESSAGE , exception . getMessage () );
3941 }
4042}
0 commit comments