Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openmrs.Provider;
import org.openmrs.api.APIException;
import org.openmrs.api.db.ProviderDAO;
import org.openmrs.api.impl.ProviderServiceImpl;

public class ProviderServiceImplTest {

Check warning on line 13 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ0-rurTiaUMPzzG9gNM&open=AZ0-rurTiaUMPzzG9gNM&pullRequest=5997
private ProviderServiceImpl service;
private ProviderDAO dao;

@BeforeEach
public void setup() {

Check warning on line 18 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ0-rurTiaUMPzzG9gNJ&open=AZ0-rurTiaUMPzzG9gNJ&pullRequest=5997
service = new ProviderServiceImpl();
dao = mock(ProviderDAO.class);
service.setProviderDAO(dao);
}

@Test
public void getProviderByUuid_shouldReturnProvider_whenProviderExists() {

Check warning on line 25 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ0-rurTiaUMPzzG9gNK&open=AZ0-rurTiaUMPzzG9gNK&pullRequest=5997
String uuid = "test-uuid";
Provider provider = new Provider();
when(dao.getProviderByUuid(uuid)).thenReturn(provider);
Provider result = service.getProviderByUuid(uuid);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra spaces

assertNotNull(result);
assertEquals(provider, result);
}

@Test
public void getProviderByUuid_shouldThrowException_whenProviderNotFound() {

Check warning on line 35 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=openmrs_openmrs-core&issues=AZ0-rurTiaUMPzzG9gNL&open=AZ0-rurTiaUMPzzG9gNL&pullRequest=5997
String uuid = "invalid-uuid";
when(dao.getProviderByUuid(uuid)).thenReturn(null);
assertThrows(APIException.class, () -> {
service.getProviderByUuid(uuid);
});
}
}