OpenmrsTestsTest.shouldHaveTestAnnotationWhenStartingWithShould:101 org.openmrs.propertyeditor.CohortEditorTest#shouldSetTheEditorValueToTheObjectAssociatedWithGivenId does not have the @Test annotation on it even though the method name starts with ‘should’ ==> expected: “true” but was: “false”
This is after introducing a new test case. below is the code.
@Test
public void setMessageSender_shouldSetMessageSender() {
MessageSender messageSender = new MessageSender() {
@Override
public void send(Message message) throws MessageException {
// TODO Auto-generated method stub
}
};
ms.setMessageSender(messageSender);
assertEquals(ms.getMessageSender(), messageSender, SET_MESSAGE_SENDER_ERROR);
}
abstract class BasePropertyEditorTest<T extends OpenmrsObject, E extends PropertyEditor> extends BaseContextSensitiveTest {
private static final String NON_EXISTING_ID = "999999";
private static final String NON_EXISTING_UUID = "9999xxxx-e131-11de-babe-001e378eb67e";
protected PropertyEditor editor;
/**
* @return a new property editor instance used in the tests
*/
protected abstract E getNewEditor();
/**
* @return an existing object for testing set as text by id and uuid
*/
protected abstract T getExistingObject();
/**
* @return a non existing object uuid for testing set as text
*/
protected String getNonExistingObjectId() {
return NON_EXISTING_ID;
}
/**
* @return a non existing object id for testing set as text
*/
protected String getNonExistingObjectUuid() {
return NON_EXISTING_UUID;
}
@BeforeEach
public void setUp() {
editor = getNewEditor();
}
@Test
public void shouldSetTheEditorValueToNullIfGivenNull() {
editor.setAsText(null);
assertNull(editor.getValue());
}
@Test
public void shouldSetTheEditorValueToNullIfGivenAnEmptyString() {
editor.setAsText(" ");
assertNull(editor.getValue());
}
@Test
public void shouldSetTheEditorValueToNullIfGivenIdDoesNotExist() {
editor.setAsText(getNonExistingObjectId());
assertNull(editor.getValue());
}
@Test
public void shouldFailToSetTheEditorValueIfGivenUuidDoesNotExist() {
assertThrows(IllegalArgumentException.class, () -> editor.setAsText(getNonExistingObjectUuid()));
}
@Test
public void shouldSetTheEditorValueToTheObjectAssociatedWithGivenId() {
editor.setAsText(getExistingObject().getId().toString());
assertThat(editor.getValue(), is(getExistingObject()));
}
@Test
public void shouldSetTheEditorValueToObjectAssociatedWithGivenUuid() {
editor.setAsText(getExistingObject().getUuid());
assertThat(editor.getValue(), is(getExistingObject()));
}
@Test
public void shouldReturnEmptyStringIfValueIsNull() {
assertThat(editor.getAsText(), is(""));
}
@Test
public void shouldReturnTheObjectIdIfValueIsNotNull() {
editor.setValue(getExistingObject());
assertThat(editor.getAsText(), is(getExistingObject().getId().toString()));
}