Skip to content

Commit

Permalink
Merge pull request #59 from denizkilic/mockListContacts
Browse files Browse the repository at this point in the history
Mock list contacts
  • Loading branch information
marcel corso gonzalez authored Jun 7, 2019
2 parents f92cd93 + 965744a commit defc2c0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ If you are using maven simply add the messagebird API to your dependencies like
<dependency>
<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
</dependency>
```

In case you are building without maven you still need maven to build the libraries but
then simply copy the following jar's over to your project

```
messagebird-api-2.1.0.jar
messagebird-api-2.1.1.jar
jackson-core-2.9.8.jar
jackson-databind-2.9.8.jar
jackson-dataformat-csv-2.9.8.jar
Expand Down
23 changes: 14 additions & 9 deletions api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>2.1.0</version> <!--
<version>2.1.2</version> <!--
are you going to bump a major number?
then you are pleased to replace com.messagebird.Base64 with some library, for example net.iharder.base64
-->
Expand Down Expand Up @@ -44,7 +42,8 @@
<connection>scm:git:[email protected]:messagebird/java-rest-api.git</connection>
<developerConnection>scm:git:[email protected]:messagebird/java-rest-api.git</developerConnection>
<url>[email protected]:messagebird/java-rest-api.git</url>
</scm>
<tag>HEAD</tag>
</scm>

<profiles>
<profile>
Expand All @@ -54,8 +53,8 @@
</activation>
<properties>
<skipTests>true</skipTests>
<messageBirdAccessKey></messageBirdAccessKey>
<messageBirdMSISDN></messageBirdMSISDN>
<messageBirdAccessKey />
<messageBirdMSISDN />
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</profile>
Expand All @@ -73,8 +72,8 @@
<properties>
<doclint>none</doclint>
<skipTests>true</skipTests>
<messageBirdAccessKey></messageBirdAccessKey>
<messageBirdMSISDN></messageBirdMSISDN>
<messageBirdAccessKey />
<messageBirdMSISDN />
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</profile>
Expand Down Expand Up @@ -102,6 +101,12 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>3.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {

private final String accessKey;
private final String serviceUrl;
private final String clientVersion = "2.1.0";
private final String clientVersion = "2.1.1";
private final String userAgentString;
private Proxy proxy = null;

Expand Down
23 changes: 17 additions & 6 deletions api/src/test/java/com/messagebird/ContactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.*;
import org.junit.*;

import org.mockito.Mockito;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;

public class ContactTest {

private static MessageBirdServiceImpl messageBirdService;
private static MessageBirdClient messageBirdClient;
private static final String CONTACTPATH = "/contacts";

private static String msisdn;

Expand Down Expand Up @@ -62,12 +65,20 @@ public static void tearDown() throws UnauthorizedException, GeneralException, No

@Test
public void testList() throws UnauthorizedException, GeneralException {
ContactList actual = messageBirdClient.listContacts();
final ContactList contactResponseList = TestUtil.createContactList();

MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
MessageBirdClient messageBirdClientInjectMock = new MessageBirdClient(messageBirdServiceMock);

when(messageBirdServiceMock.requestList(Mockito.eq(CONTACTPATH), Mockito.eq(0), Mockito.eq(20),
Mockito.eq(ContactList.class)))
.thenReturn(contactResponseList);

assertSame(20, actual.getLimit());
assertSame(0, actual.getOffset());
assertNotSame(0, actual.getTotalCount());
assertNotNull(actual.getItems().get(0).getId());
final ContactList response = messageBirdClientInjectMock.listContacts();
verify(messageBirdServiceMock, times(1))
.requestList(Mockito.eq(CONTACTPATH), Mockito.eq(0), Mockito.eq(20),
Mockito.eq(ContactList.class));
assertReflectionEquals(response.getItems().get(0),contactResponseList.getItems().get(0));
}

@Test
Expand Down
33 changes: 33 additions & 0 deletions api/src/test/java/com/messagebird/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,37 @@ static WebhookResponseData createWebhookResponseData() {
webhookResponseData.setData(Collections.singletonList(createWebhookResponse()));
return webhookResponseData;
}

private static Contact createContact(){
final CustomDetails customDetails = new CustomDetails();
customDetails.setCustom1("ANY_DETAIL");

final MessageReference messageReference = new MessageReference();
messageReference.setHREF("ANY_HREF");
messageReference.setTotalCount(30);

final GroupReference groupReference = new GroupReference();
groupReference.setHREF("ANY_HREF");
groupReference.setTotalCount(30);

final Contact contact = new Contact();
contact.setFirstName("ANY_NAME");
contact.setLastName("ANY_LAST_NAME");
contact.setId("ANY_ID");
contact.setCreatedDatetime(new Date());
contact.setMsisdn("ANY_MSISDN");
contact.setCustomDetails(customDetails);
contact.setMessages(messageReference);
contact.setHref("ANY_HREF");
contact.setGroups(groupReference);
contact.setUpdatedDatetime(new Date());

return contact;
}
static ContactList createContactList() {
final ContactList contactList = new ContactList();
contactList.setItems(Collections.singletonList(createContact()));
return contactList;
}

}
4 changes: 2 additions & 2 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.messagebird</groupId>
<artifactId>examples</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>

<licenses>
<license>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.messagebird</groupId>
<artifactId>messagebird-api</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit defc2c0

Please sign in to comment.