Skip to content

Commit a684746

Browse files
committed
Fixed: Replaced algolia exception by IllegalArgumentException
1 parent 5a8ae8d commit a684746

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

algoliasearch-common/src/main/java/com/algolia/search/APIClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,8 @@ <T> TaskSingleIndex saveObjects(String indexName, List<T> objects, RequestOption
808808
Task deleteObject(String indexName, String objectID, RequestOptions requestOptions)
809809
throws AlgoliaException {
810810

811-
if (objectID.trim().length() == 0)
812-
{
813-
throw new AlgoliaException("ObjectID must not be empty");
811+
if (objectID.trim().length() == 0) {
812+
throw new IllegalArgumentException("ObjectID must not be empty");
814813
}
815814

816815
Task result =

algoliasearch-common/src/main/java/com/algolia/search/AsyncAPIClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -788,12 +788,11 @@ <T> CompletableFuture<AsyncTaskSingleIndex> saveObjects(
788788
.thenApply(s -> s.setIndex(indexName));
789789
}
790790

791-
CompletableFuture<AsyncTask> deleteObject (
792-
String indexName, String objectID, RequestOptions requestOptions) throws AlgoliaException {
791+
CompletableFuture<AsyncTask> deleteObject(
792+
String indexName, String objectID, RequestOptions requestOptions) {
793793

794-
if (objectID.trim().length() == 0)
795-
{
796-
throw new AlgoliaException("ObjectID must not be empty");
794+
if (objectID.trim().length() == 0) {
795+
throw new IllegalArgumentException("ObjectID must not be empty");
797796
}
798797

799798
return httpClient

algoliasearch-common/src/main/java/com/algolia/search/AsyncObjects.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.algolia.search;
22

3-
import com.algolia.search.exceptions.AlgoliaException;
43
import com.algolia.search.objects.RequestOptions;
54
import com.algolia.search.objects.tasks.async.AsyncTask;
65
import com.algolia.search.objects.tasks.async.AsyncTaskIndexing;
@@ -207,7 +206,7 @@ default CompletableFuture<AsyncTaskSingleIndex> saveObjects(
207206
* @param objectID the unique identifier of the object to retrieve
208207
* @return the associated AsyncTask
209208
*/
210-
default CompletableFuture<AsyncTask> deleteObject(@Nonnull String objectID) throws AlgoliaException {
209+
default CompletableFuture<AsyncTask> deleteObject(@Nonnull String objectID) {
211210
return deleteObject(objectID, RequestOptions.empty);
212211
}
213212

@@ -218,8 +217,8 @@ default CompletableFuture<AsyncTask> deleteObject(@Nonnull String objectID) thro
218217
* @param requestOptions Options to pass to this request
219218
* @return the associated AsyncTask
220219
*/
221-
default CompletableFuture<AsyncTask> deleteObject (
222-
@Nonnull String objectID, @Nonnull RequestOptions requestOptions) throws AlgoliaException {
220+
default CompletableFuture<AsyncTask> deleteObject(
221+
@Nonnull String objectID, @Nonnull RequestOptions requestOptions) {
223222
return getApiClient().deleteObject(getName(), objectID, requestOptions);
224223
}
225224

algoliasearch-tests/src/test/java/com/algolia/search/integration/common/async/AsyncObjectsTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import java.util.List;
1212
import java.util.Optional;
1313
import java.util.concurrent.CompletableFuture;
14-
15-
import com.algolia.search.exceptions.AlgoliaException;
1614
import org.junit.Test;
1715

1816
@SuppressWarnings("ConstantConditions")
@@ -135,20 +133,20 @@ public void getObjectsWithAttributesToRetrieve() throws Exception {
135133
futureAssertThat(result).extracting("name").containsNull();
136134
}
137135

138-
@Test(expected = AlgoliaException.class)
139-
public void deleteObjectEmptyObjectIdShouldFail() throws AlgoliaException {
136+
@Test(expected = IllegalArgumentException.class)
137+
public void deleteObjectEmptyObjectIdShouldFail() throws IllegalArgumentException {
140138
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
141139
index.deleteObject("");
142140
}
143141

144-
@Test(expected = AlgoliaException.class)
145-
public void deleteObjectWhiteSpaceObjectIdShouldFail() throws AlgoliaException {
142+
@Test(expected = IllegalArgumentException.class)
143+
public void deleteObjectWhiteSpaceObjectIdShouldFail() throws IllegalArgumentException {
146144
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
147145
index.deleteObject(" ");
148146
}
149147

150148
@Test(expected = NullPointerException.class)
151-
public void deleteObjectNullObjectIdShouldFail() throws AlgoliaException {
149+
public void deleteObjectNullObjectIdShouldFail() throws NullPointerException {
152150
AsyncIndex<AlgoliaObject> index = createIndex(AlgoliaObject.class);
153151
index.deleteObject(null);
154152
}

algoliasearch-tests/src/test/java/com/algolia/search/integration/common/sync/SyncObjectsTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,22 @@ public void getObjectsWithAttributesToRetrieve() throws AlgoliaException {
131131
.isEqualToComparingFieldByField(new AlgoliaObjectWithID("1", null, 5));
132132
}
133133

134-
@Test(expected = AlgoliaException.class)
135-
public void deleteObjectEmptyObjectIdShouldFail() throws AlgoliaException {
134+
@Test(expected = IllegalArgumentException.class)
135+
public void deleteObjectEmptyObjectIdShouldFail()
136+
throws AlgoliaException, IllegalArgumentException {
136137
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
137138
index.deleteObject("");
138139
}
139140

140-
@Test(expected = AlgoliaException.class)
141-
public void deleteObjectWhiteSpaceObjectIdShouldFail() throws AlgoliaException {
141+
@Test(expected = IllegalArgumentException.class)
142+
public void deleteObjectWhiteSpaceObjectIdShouldFail()
143+
throws AlgoliaException, IllegalArgumentException {
142144
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
143145
index.deleteObject(" ");
144146
}
145147

146148
@Test(expected = NullPointerException.class)
147-
public void deleteObjectNullObjectIdShouldFail() throws AlgoliaException {
149+
public void deleteObjectNullObjectIdShouldFail() throws AlgoliaException, NullPointerException {
148150
Index<AlgoliaObject> index = createIndex(AlgoliaObject.class);
149151
index.deleteObject(null);
150152
}

0 commit comments

Comments
 (0)