Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.resend.services.automations.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

Expand All @@ -9,7 +12,7 @@
*/
public class ListAutomationRunsParams {

private final RunStatus status;
private final List<RunStatus> status;
private final Integer limit;
private final String after;
private final String before;
Expand All @@ -22,11 +25,11 @@ public ListAutomationRunsParams(Builder builder) {
}

/**
* Retrieves the status filter.
* Retrieves the status filters.
*
* @return The run status filter.
* @return The list of run status filters.
*/
public RunStatus getStatus() {
public List<RunStatus> getStatus() {
return status;
}

Expand Down Expand Up @@ -65,8 +68,11 @@ public String getBefore() {
public String toQueryString() {
Map<String, String> queryParams = new LinkedHashMap<>();

if (status != null) {
queryParams.put("status", status.getValue());
if (status != null && !status.isEmpty()) {
String statusValue = status.stream()
.map(RunStatus::getValue)
.collect(Collectors.joining(","));
queryParams.put("status", statusValue);
}
if (limit != null) {
queryParams.put("limit", limit.toString());
Expand Down Expand Up @@ -97,13 +103,36 @@ public static Builder builder() {
}

public static class Builder {
private RunStatus status;
private List<RunStatus> status;
private Integer limit;
private String after;
private String before;

public Builder status(RunStatus status) {
this.status = status;
/**
* Adds status filters.
*
* @param status The run statuses to filter by.
* @return This builder instance.
*/
public Builder status(RunStatus... status) {
if (this.status == null) {
this.status = new ArrayList<>();
}
this.status.addAll(Arrays.asList(status));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Appending to the existing builder list can mutate previously built params instances due to shared list aliasing.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java, line 121:

<comment>Appending to the existing builder list can mutate previously built params instances due to shared list aliasing.</comment>

<file context>
@@ -109,24 +109,30 @@ public static class Builder {
+            if (this.status == null) {
+                this.status = new ArrayList<>();
+            }
+            this.status.addAll(Arrays.asList(status));
             return this;
         }
</file context>

return this;
}

/**
* Adds status filters from a list.
*
* @param status The list of run statuses to filter by.
* @return This builder instance.
*/
public Builder status(List<RunStatus> status) {
if (this.status == null) {
this.status = new ArrayList<>();
}
this.status.addAll(status);
return this;
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/resend/services/automations/AutomationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ public void testListAutomationRunsWithParams_Success() throws ResendException {
verify(automations, times(1)).listRuns(automationId, params);
}

@Test
public void testListAutomationRunsWithMultipleStatuses_Success() throws ResendException {
String automationId = "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794";
ListAutomationRunsParams params = ListAutomationRunsParams.builder()
.status(RunStatus.RUNNING, RunStatus.COMPLETED)
.limit(10)
.build();

ListAutomationRunsResponseSuccess expectedResponse = AutomationsUtil.listAutomationRunsResponse();

when(automations.listRuns(automationId, params)).thenReturn(expectedResponse);

ListAutomationRunsResponseSuccess response = automations.listRuns(automationId, params);

assertNotNull(response);
assertEquals(2, params.getStatus().size());
assertEquals("?status=running,completed&limit=10", params.toQueryString());
verify(automations, times(1)).listRuns(automationId, params);
}

@Test
public void testGetAutomationRun_Success() throws ResendException {
GetAutomationRunOptions options = GetAutomationRunOptions.builder()
Expand Down
Loading