Skip to content

Commit f6cde7f

Browse files
committed
test: Add test case for empty external Id
1 parent 5717ff3 commit f6cde7f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/main/java/org/zendesk/client/v2/Zendesk.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,8 @@ public JobStatus deleteOrganizations(long... ids) {
14231423
}
14241424

14251425
public Iterable<Organization> lookupOrganizationsByExternalId(String externalId) {
1426-
if (externalId == null) {
1427-
throw new IllegalArgumentException("External ID must not be null");
1426+
if (externalId == null || externalId.length() == 0) {
1427+
throw new IllegalArgumentException("External ID must not be null or length 0");
14281428
}
14291429
return new PagedIterable<>(
14301430
tmpl("/organizations/search.json{?external_id}").set("external_id", externalId),

src/test/java/org/zendesk/client/v2/RealSmokeTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import static org.junit.Assert.assertEquals;
9898
import static org.junit.Assert.assertNotEquals;
9999
import static org.junit.Assert.assertNotNull;
100+
import static org.junit.Assert.assertThrows;
100101
import static org.junit.Assert.assertTrue;
101102
import static org.junit.Assert.assertFalse;
102103
import static org.junit.Assume.assumeThat;
@@ -1583,6 +1584,21 @@ public void createOrganizationMemberships() throws Exception {
15831584
}
15841585
}
15851586

1587+
@Test
1588+
public void lookupOrganizationByExternalId() throws Exception {
1589+
createClientWithTokenOrPassword();
1590+
1591+
Organization newOrganization = newTestOrganization();
1592+
newOrganization.setExternalId("i");
1593+
Organization resultOrganization = instance.createOrganization(newOrganization);
1594+
assertNotNull(resultOrganization);
1595+
1596+
Iterable<Organization> or = instance.lookupOrganizationsByExternalId("i");
1597+
assertTrue(or.iterator().hasNext());
1598+
1599+
assertThrows(IllegalArgumentException.class, () -> instance.lookupOrganizationsByExternalId(""));
1600+
}
1601+
15861602
@Test
15871603
public void getGroups() throws Exception {
15881604
createClientWithTokenOrPassword();

0 commit comments

Comments
 (0)