<commit_before>package org.laladev.moneyjinn.businesslogic.service.impl;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.laladev.moneyjinn.AbstractTest;
import org.laladev.moneyjinn.businesslogic.model.Contractpartner;
import org.laladev.moneyjinn.businesslogic.model.ContractpartnerID;
import org.laladev.moneyjinn.businesslogic.model.access.User;
import org.laladev.moneyjinn.businesslogic.model.access.UserID;
import org.laladev.moneyjinn.businesslogic.model.exception.BusinessException;
import org.laladev.moneyjinn.businesslogic.service.api.IContractpartnerService;
import org.laladev.moneyjinn.server.builder.ContractpartnerTransportBuilder;
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;

public class ContractpartnerServiceTest extends AbstractTest {
	@Inject
	private IContractpartnerService contractpartnerService;

	@Test(expected = IllegalArgumentException.class)
	public void test_validateNullUser_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();

		this.contractpartnerService.validateContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_createWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1L)));

		this.contractpartnerService.createContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_updateWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1L)));

		this.contractpartnerService.updateContractpartner(contractpartner);
	}

	@Test
	@Ignore("this does not work yet - see wiki TODO list")
	public void test_userAeditsContractpartner_userBsameGroupSeesCachedChange() {
		final UserID user1ID = new UserID(UserTransportBuilder.USER1_ID);
		final UserID user2ID = new UserID(UserTransportBuilder.USER2_ID);

		// this caches
		Contractpartner contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		contractpartner = this.contractpartnerService.getContractpartnerById(user2ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		final String name = String.valueOf(System.currentTimeMillis());

		contractpartner.getUser().setId(user2ID);
		contractpartner.setName(name);

		// this should also modify the cache of user 1!
		this.contractpartnerService.updateContractpartner(contractpartner);

		// this should now retrieve the changed cache entry!
		contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		Assert.assertEquals(name, contractpartner.getName());
	}
}<commit_msg>Add another cache test<commit_after>package org.laladev.moneyjinn.businesslogic.service.impl;

import java.util.List;

import javax.inject.Inject;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.laladev.moneyjinn.AbstractTest;
import org.laladev.moneyjinn.businesslogic.model.Contractpartner;
import org.laladev.moneyjinn.businesslogic.model.ContractpartnerID;
import org.laladev.moneyjinn.businesslogic.model.access.User;
import org.laladev.moneyjinn.businesslogic.model.access.UserID;
import org.laladev.moneyjinn.businesslogic.model.exception.BusinessException;
import org.laladev.moneyjinn.businesslogic.service.api.IContractpartnerService;
import org.laladev.moneyjinn.server.builder.ContractpartnerTransportBuilder;
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;

public class ContractpartnerServiceTest extends AbstractTest {
	@Inject
	private IContractpartnerService contractpartnerService;

	@Test(expected = IllegalArgumentException.class)
	public void test_validateNullUser_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();

		this.contractpartnerService.validateContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_createWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1L)));

		this.contractpartnerService.createContractpartner(contractpartner);
	}

	@Test(expected = BusinessException.class)
	public void test_updateWithInvalidEntity_raisesException() {
		final Contractpartner contractpartner = new Contractpartner();
		contractpartner.setUser(new User(new UserID(1L)));

		this.contractpartnerService.updateContractpartner(contractpartner);
	}

	@Test
	@Ignore("this does not work yet - see wiki TODO list")
	public void test_userAeditsContractpartner_userBsameGroupSeesCachedChange() {
		final UserID user1ID = new UserID(UserTransportBuilder.USER1_ID);
		final UserID user2ID = new UserID(UserTransportBuilder.USER2_ID);

		// this caches
		Contractpartner contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		contractpartner = this.contractpartnerService.getContractpartnerById(user2ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		final String name = String.valueOf(System.currentTimeMillis());

		contractpartner.getUser().setId(user2ID);
		contractpartner.setName(name);

		// this should also modify the cache of user 1!
		this.contractpartnerService.updateContractpartner(contractpartner);

		// this should now retrieve the changed cache entry!
		contractpartner = this.contractpartnerService.getContractpartnerById(user1ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		Assert.assertEquals(name, contractpartner.getName());
	}

	@Test
	@Ignore("this does not work yet - see wiki TODO list")
	public void test_userAaddsAContractpartner_userBsameGroupSeessItTooBecauseCacheWasReset() {
		final UserID user1ID = new UserID(UserTransportBuilder.USER1_ID);
		final UserID user2ID = new UserID(UserTransportBuilder.USER2_ID);

		// this caches
		final List<Contractpartner> allContractpartners1 = this.contractpartnerService.getAllContractpartners(user1ID);

		final Contractpartner contractpartner = this.contractpartnerService.getContractpartnerById(user2ID,
				new ContractpartnerID(ContractpartnerTransportBuilder.CONTRACTPARTNER1_ID));

		final String name = String.valueOf(System.currentTimeMillis());

		contractpartner.getUser().setId(user2ID);
		contractpartner.setName(name);

		// this should also modify the cache of user 1!
		this.contractpartnerService.createContractpartner(contractpartner);

		final List<Contractpartner> allContractpartners2 = this.contractpartnerService.getAllContractpartners(user1ID);

		// Cache of user1 should have been invalidated and the added Contractparter should be now in
		// the List of all partners.
		Assert.assertNotEquals(allContractpartners1.size(), allContractpartners2.size());
	}
}
{'fraction_non_alphanumeric': 0.08124035358495861, 'fraction_numerical': 0.006033394134979655, 'mean_word_length': 7.1931034482758625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1896060', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2079, 'n_words': 362}