From 6c07d4dd67147398a62064d7ec290fa450ef61c1 Mon Sep 17 00:00:00 2001 From: Sergei Prokofev Date: Fri, 15 Mar 2024 19:03:03 +0400 Subject: [PATCH] replaced raise NPE by IAE In amadeus.builder --- lombok.config | 3 ++- src/main/java/com/amadeus/Amadeus.java | 9 +++++++-- src/main/java/com/amadeus/Configuration.java | 5 +++-- src/test/java/com/amadeus/AmadeusTest.java | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lombok.config b/lombok.config index 8f7e8aa1..b7a0263e 100644 --- a/lombok.config +++ b/lombok.config @@ -1 +1,2 @@ -lombok.addLombokGeneratedAnnotation = true \ No newline at end of file +lombok.addLombokGeneratedAnnotation = true +lombok.nonNull.exceptionType = NullPointerException diff --git a/src/main/java/com/amadeus/Amadeus.java b/src/main/java/com/amadeus/Amadeus.java index 8dc63f11..ad804b4f 100644 --- a/src/main/java/com/amadeus/Amadeus.java +++ b/src/main/java/com/amadeus/Amadeus.java @@ -1,7 +1,6 @@ package com.amadeus; import java.util.Map; -import lombok.NonNull; /** *

@@ -138,7 +137,13 @@ protected Amadeus(Configuration configuration) { * @param clientSecret Your API com.amadeus.client credential secret * @return a Configuration object */ - public static Configuration builder(@NonNull String clientId, @NonNull String clientSecret) { + public static Configuration builder(String clientId, String clientSecret) { + if (clientId == null) { + throw new IllegalArgumentException("clientId can't be null"); + } + if (clientSecret == null) { + throw new IllegalArgumentException("clientSecret can't be null"); + } return new Configuration(clientId, clientSecret); } diff --git a/src/main/java/com/amadeus/Configuration.java b/src/main/java/com/amadeus/Configuration.java index c25bf246..9ac54fca 100644 --- a/src/main/java/com/amadeus/Configuration.java +++ b/src/main/java/com/amadeus/Configuration.java @@ -2,6 +2,7 @@ import java.util.Map; import java.util.logging.Logger; + import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -110,9 +111,9 @@ protected Configuration(String clientId, String clientSecret) { * Builds an Amadeus client with the provided credentials. * * @return an Amadeus client - * @throws NullPointerException when a client ID or client secret is missing + * @throws IllegalArgumentException when a client ID or client secret is missing */ - public Amadeus build() throws NullPointerException { + public Amadeus build() throws IllegalArgumentException { return new Amadeus(this); } diff --git a/src/test/java/com/amadeus/AmadeusTest.java b/src/test/java/com/amadeus/AmadeusTest.java index 3695891e..26a1a279 100644 --- a/src/test/java/com/amadeus/AmadeusTest.java +++ b/src/test/java/com/amadeus/AmadeusTest.java @@ -20,11 +20,11 @@ public class AmadeusTest { } @Test public void testBuilderWithNullClientId() { - assertThrows(NullPointerException.class, () -> Amadeus.builder(null, "secret").build()); + assertThrows(IllegalArgumentException.class, () -> Amadeus.builder(null, "secret").build()); } @Test public void testBuilderWithNullClientSecret() { - assertThrows(NullPointerException.class, () -> Amadeus.builder("client", null).build()); + assertThrows(IllegalArgumentException.class, () -> Amadeus.builder("client", null).build()); } @Test public void testBuilderWithEnvironment() {