<commit_before>/*
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

package org.openmrs.module.openhmis.cashier.api;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.BaseOpenmrsData;
import org.openmrs.api.context.Context;

import java.util.Date;

public abstract class IDataServiceTest<S extends IDataService<E>, E extends BaseOpenmrsData> extends IEntityServiceTest<S, E> {
	/**
	 * @verifies void the entity
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test
	public void voidEntity_shouldVoidTheEntity() throws Exception {
		String reason = "test void";
		E entity = service.getById(0);
		service.voidEntity(entity, reason);

		Context.flushSession();

		entity = service.getById(0);
		Assert.assertTrue(entity.getVoided());
		Assert.assertEquals(Context.getAuthenticatedUser(), entity.getVoidedBy());
		Assert.assertEquals(reason, entity.getVoidReason());
		Assert.assertTrue(entity.getDateVoided().before(new Date()));
	}

	/**
	 * @verifies throw IllegalArgumentException with null reason parameter
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test(expected = IllegalArgumentException.class)
	public void voidEntity_shouldThrowIllegalArgumentExceptionWithNullReasonParameter() throws Exception {
		E entity = service.getById(0);

		service.voidEntity(entity, null);
	}

	/**
	 * @verifies throw NullPointerException with null entity
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test(expected = NullPointerException.class)
	public void voidEntity_shouldThrowNullPointerExceptionWithNullEntity() throws Exception {
		service.voidEntity(null, "something");
	}

	/**
	 * @verifies unvoid the entity
	 * @see IDataService#unvoidEntity(org.openmrs.OpenmrsObject)
	 */
	@Test
	public void unvoidEntity_shouldUnvoidTheEntity() throws Exception {
		String reason = "test void";
		E entity = service.getById(0);
		service.voidEntity(entity, reason);

		Context.flushSession();

		entity = service.getById(0);
		Assert.assertTrue(entity.getVoided());

		service.unvoidEntity(entity);

		Context.flushSession();

		entity = service.getById(0);

		Assert.assertFalse(entity.getVoided());
		Assert.assertNull(entity.getVoidedBy());
		Assert.assertNull(entity.getVoidReason());
		Assert.assertNotNull(entity.getDateVoided()));
	}

	/**
	 * @verifies throw NullPointerException with null entity
	 * @see IDataService#unvoidEntity(org.openmrs.OpenmrsObject)
	 */
	@Test(expected = NullPointerException.class)
	public void unvoidEntity_shouldThrowNullPointerExceptionWithNullEntity() throws Exception {
		service.unvoidEntity(null);
	}
}<commit_msg>Quick fix for the data test base class.<commit_after>/*
 * The contents of this file are subject to the OpenMRS Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */

package org.openmrs.module.openhmis.cashier.api;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.BaseOpenmrsData;
import org.openmrs.api.context.Context;

import java.util.Date;

public abstract class IDataServiceTest<S extends IDataService<E>, E extends BaseOpenmrsData> extends IEntityServiceTest<S, E> {
	/**
	 * @verifies void the entity
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test
	public void voidEntity_shouldVoidTheEntity() throws Exception {
		String reason = "test void";
		E entity = service.getById(0);
		service.voidEntity(entity, reason);

		Context.flushSession();

		entity = service.getById(0);
		Assert.assertTrue(entity.getVoided());
		Assert.assertEquals(Context.getAuthenticatedUser(), entity.getVoidedBy());
		Assert.assertEquals(reason, entity.getVoidReason());
		Assert.assertTrue(entity.getDateVoided().before(new Date()));
	}

	/**
	 * @verifies throw IllegalArgumentException with null reason parameter
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test(expected = IllegalArgumentException.class)
	public void voidEntity_shouldThrowIllegalArgumentExceptionWithNullReasonParameter() throws Exception {
		E entity = service.getById(0);

		service.voidEntity(entity, null);
	}

	/**
	 * @verifies throw NullPointerException with null entity
	 * @see IDataService#voidEntity(org.openmrs.OpenmrsObject, String)
	 */
	@Test(expected = NullPointerException.class)
	public void voidEntity_shouldThrowNullPointerExceptionWithNullEntity() throws Exception {
		service.voidEntity(null, "something");
	}

	/**
	 * @verifies unvoid the entity
	 * @see IDataService#unvoidEntity(org.openmrs.OpenmrsObject)
	 */
	@Test
	public void unvoidEntity_shouldUnvoidTheEntity() throws Exception {
		String reason = "test void";
		E entity = service.getById(0);
		service.voidEntity(entity, reason);

		Context.flushSession();

		entity = service.getById(0);
		Assert.assertTrue(entity.getVoided());

		service.unvoidEntity(entity);

		Context.flushSession();

		entity = service.getById(0);

		Assert.assertFalse(entity.getVoided());
		Assert.assertNull(entity.getVoidedBy());
		Assert.assertNull(entity.getVoidReason());
		Assert.assertNotNull(entity.getDateVoided());
	}

	/**
	 * @verifies throw NullPointerException with null entity
	 * @see IDataService#unvoidEntity(org.openmrs.OpenmrsObject)
	 */
	@Test(expected = NullPointerException.class)
	public void unvoidEntity_shouldThrowNullPointerExceptionWithNullEntity() throws Exception {
		service.unvoidEntity(null);
	}
}
{'fraction_non_alphanumeric': 0.10725051562747898, 'fraction_numerical': 0.0025384737426622245, 'mean_word_length': 5.2601787487586895, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5631688', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1848, 'n_words': 459}