|
| 1 | +/* |
| 2 | + * SORMAS® - Surveillance Outbreak Response Management & Analysis System |
| 3 | + * Copyright © 2016-2022 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI) |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + * GNU General Public License for more details. |
| 12 | + * You should have received a copy of the GNU General Public License |
| 13 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 14 | + */ |
| 15 | + |
| 16 | +package de.symeda.sormas.backend.info; |
| 17 | + |
| 18 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | +import static org.hamcrest.Matchers.containsString; |
| 20 | +import static org.hamcrest.Matchers.is; |
| 21 | +import static org.hamcrest.Matchers.not; |
| 22 | + |
| 23 | +import java.lang.reflect.Field; |
| 24 | +import java.lang.reflect.Method; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +import de.symeda.sormas.api.Disease; |
| 29 | +import de.symeda.sormas.api.utils.Diseases; |
| 30 | + |
| 31 | +public class EntityColumnsTest { |
| 32 | + |
| 33 | + private static class TestDto { |
| 34 | + |
| 35 | + @Diseases(value = { |
| 36 | + Disease.GIARDIASIS, |
| 37 | + Disease.CRYPTOSPORIDIOSIS }, hide = true) |
| 38 | + private String fieldWithHide; |
| 39 | + |
| 40 | + @Diseases({ |
| 41 | + Disease.EVD, |
| 42 | + Disease.DENGUE }) |
| 43 | + private String fieldWithoutHide; |
| 44 | + |
| 45 | + private String fieldWithoutAnnotation; |
| 46 | + } |
| 47 | + |
| 48 | + private String invokeGetDiseases(String fieldName) throws Exception { |
| 49 | + EntityColumns entityColumns = new EntityColumns(null, false); |
| 50 | + Field field = TestDto.class.getDeclaredField(fieldName); |
| 51 | + FieldData fieldData = new FieldData(field, TestDto.class, "Test"); |
| 52 | + Method getDiseases = EntityColumns.class.getDeclaredMethod("getDiseases", FieldData.class); |
| 53 | + getDiseases.setAccessible(true); |
| 54 | + return (String) getDiseases.invoke(entityColumns, fieldData); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void testGetDiseases_noAnnotation_returnsAll() throws Exception { |
| 59 | + assertThat(invokeGetDiseases("fieldWithoutAnnotation"), is("All")); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testGetDiseases_withHideFalse_returnsListedDiseases() throws Exception { |
| 64 | + String result = invokeGetDiseases("fieldWithoutHide"); |
| 65 | + assertThat(result, containsString(Disease.EVD.toShortString())); |
| 66 | + assertThat(result, containsString(Disease.DENGUE.toShortString())); |
| 67 | + assertThat(result, not(containsString(Disease.GIARDIASIS.toShortString()))); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testGetDiseases_withHideTrue_returnsAllDiseasesExceptListed() throws Exception { |
| 72 | + String result = invokeGetDiseases("fieldWithHide"); |
| 73 | + assertThat(result, not(containsString(Disease.GIARDIASIS.toShortString()))); |
| 74 | + assertThat(result, not(containsString(Disease.CRYPTOSPORIDIOSIS.toShortString()))); |
| 75 | + assertThat(result, containsString(Disease.EVD.toShortString())); |
| 76 | + assertThat(result, containsString(Disease.DENGUE.toShortString())); |
| 77 | + } |
| 78 | +} |
0 commit comments