-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve 'EmbeddableBadgeConfigsActionTest' test coverage (#287)
- Loading branch information
1 parent
98bd706
commit d38681f
Showing
1 changed file
with
107 additions
and
15 deletions.
There are no files selected for viewing
122 changes: 107 additions & 15 deletions
122
src/test/java/org/jenkinsci/plugins/badge/actions/EmbeddableBadgeConfigsActionTest.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 |
---|---|---|
@@ -1,33 +1,125 @@ | ||
package org.jenkinsci.plugins.badge.actions; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsNull.nullValue; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import hudson.model.Run; | ||
import org.jenkinsci.plugins.badge.EmbeddableBadgeConfig; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class EmbeddableBadgeConfigsActionTest { | ||
class EmbeddableBadgeConfigsActionTest { | ||
|
||
EmbeddableBadgeConfigsAction embeddableBadgeConfigsAction; | ||
@Test | ||
void testGetUrlName() { | ||
// Given | ||
EmbeddableBadgeConfigsAction action = new EmbeddableBadgeConfigsAction(); | ||
|
||
// When | ||
String urlName = action.getUrlName(); | ||
|
||
// Then | ||
assertEquals("", urlName, "UrlName should be an empty string"); | ||
} | ||
|
||
@Test | ||
void testGetDisplayName() { | ||
// Given | ||
EmbeddableBadgeConfigsAction action = new EmbeddableBadgeConfigsAction(); | ||
|
||
// When | ||
String displayName = action.getDisplayName(); | ||
|
||
// Then | ||
assertEquals("", displayName, "DisplayName should be an empty string"); | ||
} | ||
|
||
@Test | ||
void testGetIconFileName() { | ||
// Given | ||
EmbeddableBadgeConfigsAction action = new EmbeddableBadgeConfigsAction(); | ||
|
||
// When | ||
String iconFileName = action.getIconFileName(); | ||
|
||
// Then | ||
assertNull(iconFileName, "IconFileName should be null"); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
embeddableBadgeConfigsAction = new EmbeddableBadgeConfigsAction(); | ||
@Test | ||
void testResolveWithValidId() { | ||
// Given | ||
Run<?, ?> run = mock(Run.class); | ||
EmbeddableBadgeConfigsAction action = mock(EmbeddableBadgeConfigsAction.class); | ||
when(run.getAction(EmbeddableBadgeConfigsAction.class)).thenReturn(action); | ||
String id = "someId"; | ||
EmbeddableBadgeConfig expectedConfig = mock(EmbeddableBadgeConfig.class); | ||
when(action.getConfig(id)).thenReturn(expectedConfig); | ||
|
||
// When | ||
EmbeddableBadgeConfig actualConfig = EmbeddableBadgeConfigsAction.resolve(run, id); | ||
|
||
// Then | ||
assertEquals(expectedConfig, actualConfig); | ||
} | ||
|
||
@Test | ||
void testResolveWithNullId() { | ||
// Given | ||
Run<?, ?> run = mock(Run.class); | ||
|
||
// When | ||
EmbeddableBadgeConfig actualConfig = EmbeddableBadgeConfigsAction.resolve(run, null); | ||
|
||
// Then | ||
assertNull(actualConfig); | ||
} | ||
|
||
@Test | ||
public void getUrlNameTest() { | ||
assertThat(embeddableBadgeConfigsAction.getUrlName(), is("")); | ||
void testResolveWithNullAction() { | ||
// Given | ||
Run<?, ?> run = mock(Run.class); | ||
when(run.getAction(EmbeddableBadgeConfigsAction.class)).thenReturn(null); | ||
String id = "someId"; | ||
|
||
// When | ||
EmbeddableBadgeConfig actualConfig = EmbeddableBadgeConfigsAction.resolve(run, id); | ||
|
||
// Then | ||
assertNull(actualConfig); | ||
} | ||
|
||
@Test | ||
public void getDisplayNameTest() { | ||
assertThat(embeddableBadgeConfigsAction.getDisplayName(), is("")); | ||
void testGetConfig() { | ||
// Given | ||
EmbeddableBadgeConfigsAction action = new EmbeddableBadgeConfigsAction(); | ||
EmbeddableBadgeConfig config = mock(EmbeddableBadgeConfig.class); | ||
when(config.getID()).thenReturn("someId"); | ||
action.addConfig(config); | ||
|
||
// When | ||
EmbeddableBadgeConfig actualConfig = action.getConfig("someId"); | ||
|
||
// Then | ||
assertNotNull(actualConfig, "Config should not be null"); | ||
assertEquals(config, actualConfig, "Config objects should be equal"); | ||
assertEquals("someId", actualConfig.getID(), "Config ID should match"); | ||
} | ||
|
||
@Test | ||
public void getIconFileNameTest() { | ||
assertThat(embeddableBadgeConfigsAction.getIconFileName(), is(nullValue())); | ||
void testAddConfig() { | ||
// Given | ||
EmbeddableBadgeConfigsAction action = new EmbeddableBadgeConfigsAction(); | ||
EmbeddableBadgeConfig config = mock(EmbeddableBadgeConfig.class); | ||
when(config.getID()).thenReturn("someId"); | ||
|
||
// When | ||
action.addConfig(config); | ||
|
||
// Then | ||
EmbeddableBadgeConfig actualConfig = action.getConfig("someId"); | ||
assertNotNull(actualConfig, "Config should not be null"); | ||
assertEquals(config, actualConfig, "Config objects should be equal"); | ||
assertEquals("someId", actualConfig.getID(), "Config ID should match"); | ||
} | ||
} |