<commit_before>package com.github.maximilientyc.conversations.commands;

import com.github.maximilientyc.conversations.domain.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

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

/**
 * Created by @maximilientyc on 07/02/2016.
 */
public class ConversationIntegrationTest {

	@Rule
	public ExpectedException expectedException;
	public MessageRepository messageRepository;
	public ConversationRepository conversationRepository;
	private ConversationService conversationService;
	private ConversationFactory conversationFactory;
	private ParticipantFactory participantFactory;
	private UserRepository userRepository;
	private UserService userService;
	private MessageFactory messageFactory;

	public ConversationIntegrationTest() {
		expectedException = ExpectedException.none();
	}

	private void initComponents() {
		try {
			prepareRepositories();
		} catch (Exception e) {
			e.printStackTrace();
		}

		conversationService = new ConversationService(conversationRepository, messageRepository);
		userRepository = new SampleUserRepository();
		userService = Mockito.mock(SampleUserService.class);
		participantFactory = new ParticipantFactory(userRepository);
		conversationFactory = new ConversationFactory(conversationService);
		messageFactory = new MessageFactory(conversationService);
	}

	public void prepareRepositories() throws Exception {
		conversationRepository = new SampleConversationRepository();
		messageRepository = new SampleMessageRepository();
	}

	@Before
	public void prepareLoggedInUser() {
		initComponents();
		Mockito.when(userService.getLoggedInUserId()).thenReturn("max");
	}

	@Test
	public void should_contain_one_conversation() {
		// given
		Set<String> userIdSet = new HashSet<String>();
		userIdSet.add("max");
		userIdSet.add("bob");
		CreateConversationCommand createConversationCommand = new CreateConversationCommand(userIdSet, conversationFactory, participantFactory, conversationRepository, userService);

		// when
		Conversation conversation = createConversationCommand.execute();
		String conversationId = conversation.getConversationId();

		// then
		long conversationCount = conversationService.countConversations();
		assertThat(conversationCount).isEqualTo(1);
	}
<commit_msg>quick refactor on conversation integration test<commit_after>package com.github.maximilientyc.conversations.commands;

import com.github.maximilientyc.conversations.domain.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

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

/**
 * Created by @maximilientyc on 07/02/2016.
 */
public class ConversationIntegrationTest {

	@Rule
	public ExpectedException expectedException;
	public MessageRepository messageRepository;
	public ConversationRepository conversationRepository;
	private ConversationService conversationService;
	private ConversationFactory conversationFactory;
	private ParticipantFactory participantFactory;
	private UserRepository userRepository;
	private UserService userService;
	private MessageFactory messageFactory;

	public ConversationIntegrationTest() {
		expectedException = ExpectedException.none();
	}

	@Before
	public void initComponents() {
		try {
			prepareRepositories();
		} catch (Exception e) {
			e.printStackTrace();
		}

		conversationService = new ConversationService(conversationRepository, messageRepository);
		userRepository = new SampleUserRepository();
		userService = Mockito.mock(SampleUserService.class);
		participantFactory = new ParticipantFactory(userRepository);
		conversationFactory = new ConversationFactory(conversationService);
		messageFactory = new MessageFactory(conversationService);

		Mockito.when(userService.getLoggedInUserId()).thenReturn("max");
	}

	public void prepareRepositories() throws Exception {
		conversationRepository = new SampleConversationRepository();
		messageRepository = new SampleMessageRepository();
	}

	@Test
	public void should_contain_one_conversation() {
		// given
		Set<String> userIdSet = new HashSet<String>();
		userIdSet.add("max");
		userIdSet.add("bob");
		CreateConversationCommand createConversationCommand = new CreateConversationCommand(userIdSet, conversationFactory, participantFactory, conversationRepository, userService);

		// when
		Conversation conversation = createConversationCommand.execute();
		String conversationId = conversation.getConversationId();

		// then
		long conversationCount = conversationService.countConversations();
		assertThat(conversationCount).isEqualTo(1);
	}

{'fraction_non_alphanumeric': 0.08564386937769562, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 6.633228840125392, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2020951', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1261, 'n_words': 277}