Skip to content

Commit

Permalink
Added tests for GetSubject to increase test coverage (#272)
Browse files Browse the repository at this point in the history
* Added tests for GetSubject

* Increasing test coverage with adding setSubject(String), setLink(String) and setColor(String).

* Apply suggestions from code review

Co-authored-by: Mark Waite <[email protected]>

* Update src/test/java/org/jenkinsci/plugins/badge/EmbeddableBadgeConfigTest.java

Co-authored-by: Mark Waite <[email protected]>

* Format code

---------

Co-authored-by: Mark Waite <[email protected]>
  • Loading branch information
devc007 and MarkEWaite authored Dec 18, 2023
1 parent f49592e commit 18ffed5
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,59 @@ public void testGetColor(String status, String expected) {
embeddableBadgeConfig.setStatus(status);
assertThat(embeddableBadgeConfig.getColor(), is(expected));
}

@Test
public void testSetSubject() {
String subject = "Test Subject";
EmbeddableBadgeConfig embeddableBadgeConfig = new EmbeddableBadgeConfig("testId-subject");
embeddableBadgeConfig.setSubject(subject);
assertThat(embeddableBadgeConfig.getSubject(), is(subject));
}

@Test
public void testSetValidLink() {
String link = "https://jenkins.io";
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-valid-link");
config.setLink(link);
assertThat(config.getLink(), is(link));
}

@Test
public void testSetEmptyLink() {
String link = "";
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-empty-link");
config.setLink(link);
assertThat(config.getLink(), is(link));
}

@Test
public void testSetValidDefaultColor() {
String color = "red";
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-valid-default-color");
config.setColor(color);
assertThat(config.getColor(), is(color));
}

@Test
public void testSetValidCustomColor() {
String color = "#ff00ff"; // Magenta
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-valid-custom-color");
config.setColor(color);
assertThat(config.getColor(), is(color));
}

@Test
public void testSetEmptyColor() {
String color = "";
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-empty-color");
config.setColor(color);
assertThat(config.getColor(), is(""));
}

@Test
public void testSetNullColor() {
EmbeddableBadgeConfig config = new EmbeddableBadgeConfig("test-null-color");
config.setColor(null);
assertThat(config.getColor(), is(nullValue()));
}
}

0 comments on commit 18ffed5

Please sign in to comment.