Skip to content

Commit

Permalink
add SlackEventMessageDeserializationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ykaliukh committed Apr 4, 2024
1 parent 95f03e3 commit 203caf6
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.hubspot.slack.client.models.events.includingfiles;

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.core.type.TypeReference;
import com.hubspot.slack.client.jackson.ObjectMapperUtils;
import com.hubspot.slack.client.models.JsonLoader;
import com.hubspot.slack.client.models.events.SlackEventType;
import com.hubspot.slack.client.models.events.SlackEventWrapper;
import java.io.IOException;
import org.junit.Test;

public class SlackEventMessageDeserializationTest {

@Test
public void itDeserializes() throws IOException {
SlackEventMessage slackEvent = fetchAndDeserializeSlackEvent(
"message_shared_with_file.json"
);
assertThat(slackEvent.getType()).isEqualTo(SlackEventType.MESSAGE);
assertThat(slackEvent.getFiles().size()).isEqualTo(2);
}

private SlackEventMessage fetchAndDeserializeSlackEvent(String jsonFileName)
throws IOException {
String rawJson = JsonLoader.loadJsonFromFile(jsonFileName);
return deserializeSlackEvent(rawJson);
}

private SlackEventMessage deserializeSlackEvent(String rawJson) throws IOException {
SlackEventWrapper<SlackEventMessage> eventWrapper = ObjectMapperUtils
.mapper()
.readValue(rawJson, new TypeReference<>() {});
return eventWrapper.getEvent();
}
}

0 comments on commit 203caf6

Please sign in to comment.