Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ The new test code is implemented using Scala. The prod code is only Java - to av
| PUT /1/cards/[card id or shortlink]/pos
| PUT /1/cards/[card id or shortlink]/subscribed
| PUT /1/cards/[card id or shortlink]/warnWhenUpcoming
| PUT /1/cards/[card id or shortlink]/checkItem/[idCheckItem] | Yes | Yes | No
| POST /1/cards | Yes
| POST /1/cards/[card id or shortlink]/actions/comments | Yes | No | Yes
| POST /1/cards/[card id or shortlink]/attachments | Yes <br> (Except AsyncTrelloHttpClient) | No | Yes
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/julienvey/trello/Trello.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ List<CardWithActions> getBoardMemberActivity(String boardId, String memberId,

void createCheckItem(String checkListId, CheckItem checkItem);

CheckItem completeCheckItem(String cardId, String checkItemId);

CheckItem incompleteCheckItem(String cardId, String checkItemId);

List<CheckList> getCardChecklists(String cardId, Argument... args);

/* Organizations */
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/julienvey/trello/domain/CheckItem.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.julienvey.trello.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.julienvey.trello.impl.domaininternal.CheckItemState;

@JsonIgnoreProperties(ignoreUnknown = true)
public class CheckItem {

private String state;
private CheckItemState state = CheckItemState.INCOMPLETE;
private String id;
private String name;
private int pos;
Expand Down Expand Up @@ -34,11 +35,11 @@ public void setPos(int pos) {
this.pos = pos;
}

public String getState() {
public CheckItemState getState() {
return state;
}

public void setState(String state) {
public void setState(CheckItemState state) {
this.state = state;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/julienvey/trello/impl/TrelloImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static com.julienvey.trello.impl.TrelloUrl.REMOVE_MEMBER_FROM_CARD;
import static com.julienvey.trello.impl.TrelloUrl.UPDATE_CARD;
import static com.julienvey.trello.impl.TrelloUrl.UPDATE_CARD_COMMENT;
import static com.julienvey.trello.impl.TrelloUrl.UPDATE_CHECKITEM_IN_CARD;
import static com.julienvey.trello.impl.TrelloUrl.UPDATE_LABEL;
import static com.julienvey.trello.impl.TrelloUrl.createUrl;
import static com.julienvey.trello.impl.TrelloUrl.createUrlWithNoArgs;
Expand All @@ -72,6 +73,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.julienvey.trello.impl.domaininternal.CheckItemState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -443,6 +445,16 @@ public void createCheckItem(String checkListId, CheckItem checkItem) {
postForLocation(createUrl(ADD_CHECKITEMS_TO_CHECKLIST).asString(), checkItem, checkListId);
}

public CheckItem completeCheckItem(String cardId, String checkItemId) {
Map<String, String> body = Map.of("state", CheckItemState.COMPLETE.getState());
return put(createUrl(UPDATE_CHECKITEM_IN_CARD).asString(), body, CheckItem.class, cardId, checkItemId);
}

public CheckItem incompleteCheckItem(String cardId, String checkItemId) {
Map<String, String> body = Map.of("state", CheckItemState.INCOMPLETE.getState());
return put(createUrl(UPDATE_CHECKITEM_IN_CARD).asString(), body, CheckItem.class, cardId, checkItemId);
}

/* Others */

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/julienvey/trello/impl/TrelloUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class TrelloUrl {
public static final String GET_CHECK_LIST = "/checklists/{checkListId}?";
public static final String CREATE_CHECKLIST = "/checklists?";
public static final String ADD_CHECKITEMS_TO_CHECKLIST = "/checklists/{checkListId}/checkitems?";
public static final String UPDATE_CHECKITEM_IN_CARD = "/cards/{cardId}/checkitem/{checkItemId}?";

public static final String CREATE_CARD = "/cards?pos=top&";
public static final String GET_MEMBER = "/members/{username}?";
Expand Down Expand Up @@ -104,4 +105,4 @@ public String asString() {
}
return builder.toString();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.julienvey.trello.impl.domaininternal;

import com.fasterxml.jackson.annotation.JsonValue;

public enum CheckItemState {
COMPLETE("complete"),
INCOMPLETE("incomplete");

private final String state;

CheckItemState(String state) {
this.state = state;
}

@JsonValue
public String getState() {
return state;
}
}
52 changes: 0 additions & 52 deletions src/test/java/com/julienvey/trello/unit/CheckListGetUnitTest.java

This file was deleted.

98 changes: 98 additions & 0 deletions src/test/java/com/julienvey/trello/unit/CheckListUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.julienvey.trello.unit;

import com.julienvey.trello.Trello;
import com.julienvey.trello.TrelloHttpClient;
import com.julienvey.trello.domain.CheckItem;
import com.julienvey.trello.domain.CheckList;
import com.julienvey.trello.impl.TrelloImpl;
import com.julienvey.trello.impl.domaininternal.CheckItemState;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.Map;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.anyVararg;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

public class CheckListUnitTest {

private Trello trello;

private TrelloHttpClient httpClient;

@Before
public void setUp() {
httpClient = Mockito.mock(TrelloHttpClient.class);
trello = new TrelloImpl("", "", httpClient);
}

@Test
public void testGetCheckList() {
//Given
CheckList mockCheckList = new CheckList();
mockCheckList.setId("idCheckList");

when(httpClient.get(anyString(), any(Class.class), (String[]) anyVararg())).thenReturn(mockCheckList);

//When
CheckList checkList = trello.getCheckList("idCheckList");

//Then
assertThat(checkList).isNotNull();
assertThat(checkList.getId()).isEqualTo("idCheckList");

verify(httpClient).get(eq("https://api.trello.com/1/checklists/{checkListId}?key={applicationKey}&token={userToken}"),
eq(CheckList.class), eq("idCheckList"), eq(""), eq(""));
verifyNoMoreInteractions(httpClient);
}

@Test
public void testCompleteCheckItemInCheckList() {
//Given
CheckItem mockCheckItem = mockCheckItem(CheckItemState.COMPLETE);
when(httpClient.putForObject(anyString(), any(Class.class), any(), anyVararg())).thenReturn(mockCheckItem);

//When
CheckItem checkItem = trello.completeCheckItem("idCheckList", "idCheckItem");

//Then
verifyCheckItemAndRequest(checkItem, CheckItemState.COMPLETE);
}

@Test
public void testIncompleteCheckItemInCheckList() {
//Given
CheckItem mockCheckItem = mockCheckItem(CheckItemState.INCOMPLETE);
when(httpClient.putForObject(anyString(), any(Class.class), any(), anyVararg())).thenReturn(mockCheckItem);

//When
CheckItem checkItem = trello.incompleteCheckItem("idCheckList", "idCheckItem");

//Then
verifyCheckItemAndRequest(checkItem, CheckItemState.INCOMPLETE);
}

private void verifyCheckItemAndRequest(CheckItem checkItem, CheckItemState state) {
assertThat(checkItem).isNotNull();
assertThat(checkItem.getId()).isEqualTo("idCheckItem");
assertThat(checkItem.getState()).isEqualTo(state);

verify(httpClient).putForObject(eq("https://api.trello.com/1/cards/{cardId}/checkitem/{checkItemId}?key={applicationKey}&token={userToken}"),
eq(Map.of("state", state.getState())), eq(CheckItem.class), eq("idCheckList"), eq("idCheckItem"), eq(""), eq(""));
verifyNoMoreInteractions(httpClient);
}

private CheckItem mockCheckItem(CheckItemState state) {
CheckItem mockCheckItem = new CheckItem();
mockCheckItem.setId("idCheckItem");
mockCheckItem.setState(state);
return mockCheckItem;
}
}