From e9024edb751ce0a7ee94cbe9a1f5bd85785d6730 Mon Sep 17 00:00:00 2001 From: Yash Pal Date: Sun, 27 Oct 2024 23:08:57 +0530 Subject: [PATCH] Added Tests for ParameterResolver in the ParameterResolverTest class Added more automated tests for ParameterResolverTest class --- .../plugins/badge/ParameterResolverTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java b/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java index 90b434493..aac0420f2 100644 --- a/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java +++ b/src/test/java/org/jenkinsci/plugins/badge/ParameterResolverTest.java @@ -19,4 +19,55 @@ void shouldResolveSubjectWithVariables(String queryParameter, String expectedPar String resolvedParameter = new ParameterResolver().resolve(Mockito.mock(Actionable.class), queryParameter); assertThat(resolvedParameter, is(expectedParameter)); } + + void shouldResolveNullParameter() { + String resolvedParameter = new ParameterResolver().resolve(Mockito.mock(Actionable.class), null); + assertThat(resolvedParameter, is(null)); + } + + void shouldResolveEmptyParameter() { + String resolvedParameter = new ParameterResolver().resolve(Mockito.mock(Actionable.class), ""); + assertThat(resolvedParameter, is("")); + } + + void shouldResolveParameterWithoutVariables() { + String resolvedParameter = new ParameterResolver().resolve(Mockito.mock(Actionable.class), "Build"); + assertThat(resolvedParameter, is("Build")); + } + + void shouldResolveParameterWithVariables() { + String resolvedParameter = + new ParameterResolver().resolve(Mockito.mock(Actionable.class), "Build ${params.BUILD_BRANCH}"); + assertThat(resolvedParameter, is("Build params.BUILD_BRANCH")); + } + + void shouldResolveParameterWithVariablesAndText() { + String resolvedParameter = new ParameterResolver() + .resolve(Mockito.mock(Actionable.class), "Build ${params.BUILD_BRANCH} (${displayName})"); + assertThat(resolvedParameter, is("Build params.BUILD_BRANCH (displayName)")); + } + + void shouldResolveParameterWithVariablesAndTextAndDefault() { + String resolvedParameter = new ParameterResolver() + .resolve(Mockito.mock(Actionable.class), "Build ${params.BUILD_BRANCH|master} (${displayName})"); + assertThat(resolvedParameter, is("Build params.BUILD_BRANCH|master (displayName)")); + } + + void shouldNotResolveParameterOfVaryingLengthInRegex() { + ParameterResolver resolver = new ParameterResolver(); + String resolvedParameter = resolver.resolve(Mockito.mock(Actionable.class), "(?<=\\w*)"); + assertThat(resolvedParameter, is("(?<=\\w*)")); + } + + void shouldNotResolveParameterWithFullRangeUnicode(){ + String resolvedParameter = new ParameterResolver() + .resolve(Mockito.mock(Actionable.class), "\\p{InGreek}"); + assertThat(resolvedParameter, is("\\p{InGreek}")); + } + + void shouldNotResolveParameterWithRegexInlineFlags(){ + String resolvedParameter = new ParameterResolver() + .resolve(Mockito.mock(Actionable.class), "(${\\Build(?i) params\\b})"); + assertThat(resolvedParameter, is("(${\\Build(?i) params\\b})")); + } }