-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional custom settings validation (#93)
Refs: #91
- Loading branch information
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/java/ch/sbb/polarion/extension/interceptor_manager/settings/HookSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch.sbb.polarion.extension.interceptor_manager.settings; | ||
|
||
import ch.sbb.polarion.extension.generic.settings.SettingsService; | ||
import ch.sbb.polarion.extension.interceptor_manager.model.ActionHook; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class HookSettingsTest { | ||
|
||
@Test | ||
public void testValidate() { | ||
ActionHook hook = mock(ActionHook.class); | ||
|
||
HookModel hookModel = mock(HookModel.class); | ||
HookSettings settings = new HookSettings(hook, mock(SettingsService.class)); | ||
|
||
settings.beforeSave(hookModel); | ||
verify(hook, times(1)).validateSettings(any()); | ||
|
||
when(hook.validateSettings(any())).thenReturn("Some validation error"); | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> settings.beforeSave(hookModel)); | ||
assertEquals("Some validation error", exception.getMessage()); | ||
verify(hook, times(2)).validateSettings(any()); | ||
} | ||
} |