Skip to content

Commit

Permalink
fix:clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverD3 committed Oct 8, 2024
1 parent 3145d2b commit be6645b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
29 changes: 28 additions & 1 deletion src/main/java/org/isf/settings/enums/SettingValueType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
/*
* Open Hospital (www.open-hospital.org)
* Copyright © 2006-2023 Informatici Senza Frontiere ([email protected])
*
* Open Hospital is a free and open source software for healthcare data management.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.isf.settings.enums;

/**
* Setting Value Type Enum
* @author Silevester D.
* @since v1.15
*/
public enum SettingValueType {
bool, number, text, select;
bool, number, text, select
}
4 changes: 2 additions & 2 deletions src/main/java/org/isf/settings/manager/SettingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public Setting update(Setting setting) throws OHServiceException {
return operations.save(setting);
}

public Setting getByCode(String code) throws OHServiceException {
public Setting getByCode(String code) {
return operations.getByCode(code);
}

public Setting getById(int id) throws OHServiceException {
public Setting getById(int id) {
return operations.getById(id);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/isf/settings/model/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ public void setDeleted(Boolean deleted) {
this.deleted = deleted;
}

public Boolean getEditable() {
return isEditable;
}
public Boolean getEditable() { return isEditable; }

public void setEditable(Boolean editable) {
isEditable = editable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public Setting save(Setting setting) throws OHServiceException {
return repository.save(setting);
}

public Setting getByCode(String code) throws OHServiceException {
public Setting getByCode(String code) {
return repository.findFirstByCodeAndDeleted(code, false);
}

public Setting getById(int id) throws OHServiceException {
public Setting getById(int id) {
return repository.findFirstByIdAndDeleted(id, false);
}

Expand Down
35 changes: 15 additions & 20 deletions src/test/java/org/isf/settings/manager/SettingManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,19 @@
import java.util.List;

import org.isf.OHCoreTestCase;
import org.isf.menu.TestPermission;
import org.isf.menu.TestUserGroup;
import org.isf.menu.manager.UserBrowsingManager;
import org.isf.menu.model.UserGroup;
import org.isf.permissions.manager.GroupPermissionManager;
import org.isf.permissions.manager.PermissionManager;
import org.isf.permissions.model.GroupPermission;
import org.isf.permissions.model.Permission;
import org.isf.settings.model.Setting;
import org.isf.utils.exception.OHDataValidationException;
import org.isf.utils.exception.OHException;
import org.isf.utils.exception.OHServiceException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Setting Manager Tests
* @author Silevester D.
* @since v1.15
*/
public class SettingManagerTest extends OHCoreTestCase {

@Autowired
Expand All @@ -67,7 +63,7 @@ void testGetAllSettings() throws OHServiceException {

@Test
@DisplayName("Get setting by ID")
void testGetSettingById() throws OHServiceException {
void testGetSettingById() {
Setting setting = manager.getById(1);

assertThat(setting).isNotNull();
Expand All @@ -76,23 +72,23 @@ void testGetSettingById() throws OHServiceException {

@Test
@DisplayName("Get deleted setting by ID")
void testGetDeletedSettingById() throws OHServiceException {
void testGetDeletedSettingById() {
Setting setting = manager.getById(56);

assertThat(setting).isNull();
}

@Test
@DisplayName("Get non existing setting by ID")
void testGetNonExistingSettingById() throws OHServiceException {
void testGetNonExistingSettingById() {
Setting setting = manager.getById(156);

assertThat(setting).isNull();
}

@Test
@DisplayName("Get setting by Code")
void testGetSettingByCode() throws OHServiceException {
void testGetSettingByCode() {
Setting setting = manager.getByCode("SINGLEUSER");

assertThat(setting).isNotNull();
Expand All @@ -101,15 +97,15 @@ void testGetSettingByCode() throws OHServiceException {

@Test
@DisplayName("Get deleted setting by Code")
void testGetDeletedSettingByCode() throws OHServiceException {
void testGetDeletedSettingByCode() {
Setting setting = manager.getByCode("MODE");

assertThat(setting).isNull();
}

@Test
@DisplayName("Get non existing setting by Code")
void testGetNonExistingSettingByCode() throws OHServiceException {
void testGetNonExistingSettingByCode() {
Setting setting = manager.getByCode("MODEMODE");

assertThat(setting).isNull();
Expand All @@ -134,14 +130,12 @@ void testUpdateSetting() throws OHServiceException {

@Test
@DisplayName("Update non editable setting")
void testUpdateNonEditableSetting() throws OHServiceException {
void testUpdateNonEditableSetting() {
Setting setting = manager.getById(1);

setting.setValue("TRUE");

assertThatThrownBy(() -> {
manager.update(setting);
}).isInstanceOf(OHDataValidationException.class);
assertThatThrownBy(() -> manager.update(setting)).isInstanceOf(OHDataValidationException.class);
}

@Test
Expand All @@ -155,9 +149,10 @@ void testResetAllSettingsToDefault() throws OHServiceException {
setting = manager.update(setting);
String oldValue = setting.getValue();

manager.resetAll();
boolean reset = manager.resetAll();
Setting resetSetting = manager.getByCode("USERSLISTLOGIN");

assertThat(reset).isTrue();
assertThat(oldValue).isNotEqualTo(resetSetting.getValue());
assertThat(resetSetting.getDefaultValue()).isEqualTo(resetSetting.getValue());
}
Expand Down

0 comments on commit be6645b

Please sign in to comment.