Skip to content

Commit

Permalink
TRUNK-5816: Migrate unit tests to Junit5 1
Browse files Browse the repository at this point in the history
  • Loading branch information
achilep authored and teleivo committed Jul 14, 2020
1 parent 0f87146 commit 39f9059
Show file tree
Hide file tree
Showing 20 changed files with 433 additions and 392 deletions.
Expand Up @@ -9,10 +9,12 @@
*/
package org.openmrs.validator;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.openmrs.hl7.HL7Source;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

Expand All @@ -31,7 +33,7 @@ public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {

Errors errors = new BindException(hl7Source, "hl7Source");
new HL7SourceValidator().validate(hl7Source, errors);
Assert.assertFalse(errors.hasErrors());
assertFalse(errors.hasErrors());
}

/**
Expand All @@ -45,6 +47,6 @@ public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {

Errors errors = new BindException(hl7Source, "hl7Source");
new HL7SourceValidator().validate(hl7Source, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("name"));
}
}
Expand Up @@ -9,12 +9,16 @@
*/
package org.openmrs.validator;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.jupiter.api.Test;
import org.openmrs.ImplementationId;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

Expand All @@ -31,10 +35,10 @@ public class ImplementationIdValidatorTest extends BaseContextSensitiveTest {
public void validate_shouldThrowAPIExceptionIfImplementationIdIsNUll() {
try {
new ImplementationIdValidator().validate(null, null);
Assert.fail();
fail();
}
catch (APIException e) {
Assert.assertEquals(e.getMessage(), Context.getMessageSourceService().getMessage("ImplementationId.null"));
assertEquals(e.getMessage(), Context.getMessageSourceService().getMessage("ImplementationId.null"));
}
}

Expand All @@ -50,9 +54,9 @@ public void validate_shouldFailValidationIfImplementationIdIsNull() {
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);

Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("passphrase"));
Assert.assertFalse(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("implementationId"));
assertFalse(errors.hasFieldErrors("passphrase"));
assertFalse(errors.hasFieldErrors("description"));
}

/**
Expand All @@ -67,9 +71,9 @@ public void validate_shouldPassValidationIfDescriptionIsNull() {
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);

Assert.assertFalse(errors.hasFieldErrors("description"));
Assert.assertFalse(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("passphrase"));
assertFalse(errors.hasFieldErrors("description"));
assertFalse(errors.hasFieldErrors("implementationId"));
assertFalse(errors.hasFieldErrors("passphrase"));
}

/**
Expand All @@ -84,9 +88,9 @@ public void validate_shouldFailValidationIfPassPhraseIsNull() {
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);

Assert.assertTrue(errors.hasFieldErrors("passphrase"));
Assert.assertFalse(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("passphrase"));
assertFalse(errors.hasFieldErrors("implementationId"));
assertFalse(errors.hasFieldErrors("description"));
}

/**
Expand All @@ -99,9 +103,9 @@ public void validate_shouldFailIfGivenEmptyImplementationIdObject() {
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);

Assert.assertTrue(errors.hasFieldErrors("passphrase"));
Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("passphrase"));
assertTrue(errors.hasFieldErrors("implementationId"));
assertFalse(errors.hasFieldErrors("description"));
}

/**
Expand All @@ -117,8 +121,8 @@ public void validate_shouldFailIfGivenACaretInTheImplementationIdCode() {
Errors errors = new BindException(invalidId, "implementationId");
new ImplementationIdValidator().validate(invalidId, errors);

Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId")
assertTrue(errors.hasFieldErrors("implementationId"));
assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId")
.getCode());
}

Expand All @@ -136,8 +140,8 @@ public void validate_shouldFailIfGivenAPipeInTheImplementationIdCode() {
Errors errors = new BindException(invalidId2, "implementationId");
new ImplementationIdValidator().validate(invalidId2, errors);

Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId")
assertTrue(errors.hasFieldErrors("implementationId"));
assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId")
.getCode());
}

Expand All @@ -154,10 +158,10 @@ public void validate_shouldFailValidationIfNameIsNull() {
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);

Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertFalse(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("passphrase"));
Assert.assertFalse(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("name"));
assertFalse(errors.hasFieldErrors("implementationId"));
assertFalse(errors.hasFieldErrors("passphrase"));
assertFalse(errors.hasFieldErrors("description"));
}

}
Expand Up @@ -9,12 +9,15 @@
*/
package org.openmrs.validator;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openmrs.LocationAttributeType;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

Expand All @@ -32,7 +35,7 @@ public class LocationAttributeTypeValidatorTest extends BaseContextSensitiveTest
*
* @throws Exception
*/
@Before
@BeforeEach
public void runBeforeEachTest() {
executeDataSet(LOC_ATTRIBUTE_DATA_XML);
}
Expand All @@ -48,17 +51,17 @@ public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {

Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("name"));

type.setName("");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("name"));

type.setName(" ");
errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("name"));
}

/**
Expand All @@ -73,7 +76,7 @@ public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);

Assert.assertFalse(errors.hasErrors());
assertFalse(errors.hasErrors());
}

/**
Expand All @@ -82,14 +85,14 @@ public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
@Test
public void validate_shouldFailIfLocationAttributeTypeNameIsDuplicate() {

Assert.assertNotNull(Context.getLocationService().getLocationAttributeTypeByName("Audit Date"));
assertNotNull(Context.getLocationService().getLocationAttributeTypeByName("Audit Date"));

LocationAttributeType type = new LocationAttributeType();
type.setName("Audit Date");
type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
Errors errors = new BindException(type, "locationAttributeType");
new LocationAttributeTypeValidator().validate(type, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("name"));

}

Expand All @@ -100,10 +103,10 @@ public void validate_shouldFailIfLocationAttributeTypeNameIsDuplicate() {
public void validate_shouldPassEditingLocationAttributeTypeName() {

LocationAttributeType et = Context.getLocationService().getLocationAttributeTypeByName("Audit Date");
Assert.assertNotNull(et);
assertNotNull(et);
Errors errors = new BindException(et, "locationAttributeType");
new LocationAttributeTypeValidator().validate(et, errors);
Assert.assertFalse(errors.hasErrors());
assertFalse(errors.hasErrors());

}

Expand All @@ -121,7 +124,7 @@ public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);

Assert.assertFalse(errors.hasErrors());
assertFalse(errors.hasErrors());
}

/**
Expand All @@ -144,10 +147,10 @@ public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Errors errors = new BindException(type, "type");
new LocationAttributeTypeValidator().validate(type, errors);

Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("datatypeClassname"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("preferredHandlerClassname"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("datatypeClassname"));
assertTrue(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("preferredHandlerClassname"));
assertTrue(errors.hasFieldErrors("retireReason"));
}
}
Expand Up @@ -9,10 +9,12 @@
*/
package org.openmrs.validator;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.openmrs.LocationTag;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;

Expand All @@ -35,7 +37,7 @@ public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Errors errors = new BindException(locationTag, "locationTag");
new LocationTagValidator().validate(locationTag, errors);

Assert.assertFalse(errors.hasErrors());
assertFalse(errors.hasErrors());
}

/**
Expand All @@ -55,8 +57,8 @@ public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Errors errors = new BindException(locationTag, "location");
new LocationTagValidator().validate(locationTag, errors);

Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertTrue(errors.hasFieldErrors("description"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
assertTrue(errors.hasFieldErrors("name"));
assertTrue(errors.hasFieldErrors("description"));
assertTrue(errors.hasFieldErrors("retireReason"));
}
}

0 comments on commit 39f9059

Please sign in to comment.