Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Merge branch 'JENKINS-50066/UnitTest-HealthReportBuilder' into hm-edu…
Browse files Browse the repository at this point in the history
…-testing
  • Loading branch information
loelala committed Apr 12, 2018
2 parents edcf83d + c5cb979 commit 80e06c3
Showing 1 changed file with 61 additions and 55 deletions.
Expand Up @@ -10,7 +10,8 @@
import hudson.model.HealthReport;

/**
* Test {@link HealthReportBuilder}
* Test {@link HealthReportBuilder}.
*
* @author alexandra wenzel
*/
class HealthReportBuilderTest {
Expand All @@ -20,56 +21,53 @@ class HealthReportBuilderTest {
private static final String DESCRIPTION_MESSAGE_ENDING_PLURAL = " warnings found.";
private static final String DESCRIPTION_MESSAGE_ENDING_SINGULAR = " warning found.";



/**
* Tests whether we evaluate correctly to a 50% health.
*/
@Test
void test50Health() {
HealthReport reportHighPrio = createTestHealthReport(4, 16, Priority.HIGH,10, 20, 30);
HealthReport reportNormalPrio = createTestHealthReport(15, 45, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPrio = createTestHealthReport(15, 105, Priority.LOW, 10, 20, 30);


assertThat(reportHighPrio.getScore()).isEqualTo(50);
assertThat(reportNormalPrio.getScore()).isEqualTo(50);
assertThat(reportLowPrio.getScore()).isEqualTo(50);
void shouldTest50Health() {
HealthReport reportHighPriority = createTestHealthReport(4, 16, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPriority = createTestHealthReport(15, 45, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPriority = createTestHealthReport(15, 105, Priority.LOW, 10, 20, 30);

assertThat(reportHighPriority.getScore()).isEqualTo(50);
assertThat(reportNormalPriority.getScore()).isEqualTo(50);
assertThat(reportLowPriority.getScore()).isEqualTo(50);
}

/**
* Tests whether we evaluate correctly to 100% health.
*/
@Test
void test100Health() {
HealthReport reportHighPrio = createTestHealthReport(20, 22, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPrio = createTestHealthReport(40, 45, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPrio = createTestHealthReport(65, 105, Priority.LOW, 10, 20, 30);

assertThat(reportHighPrio.getScore()).isEqualTo(100);
assertThat(reportNormalPrio.getScore()).isEqualTo(100);
assertThat(reportLowPrio.getScore()).isEqualTo(100);
void shouldTest100Health() {
HealthReport reportHighPriority = createTestHealthReport(20, 22, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPriority = createTestHealthReport(40, 45, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPriority = createTestHealthReport(65, 105, Priority.LOW, 10, 20, 30);

assertThat(reportHighPriority.getScore()).isEqualTo(100);
assertThat(reportNormalPriority.getScore()).isEqualTo(100);
assertThat(reportLowPriority.getScore()).isEqualTo(100);
}

/**
* Test whether we evaluate correctly to 0% health.
*/
@Test
void test0Health() {
HealthReport reportHighPrio = createTestHealthReport(4, 6, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPrio = createTestHealthReport(15, 25, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPrio = createTestHealthReport(15, 45, Priority.LOW, 10, 20, 30);

assertThat(reportHighPrio.getScore()).isEqualTo(0);
assertThat(reportNormalPrio.getScore()).isEqualTo(0);
assertThat(reportLowPrio.getScore()).isEqualTo(0);
void shouldTest0Health() {
HealthReport reportHighPriority = createTestHealthReport(4, 6, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPriority = createTestHealthReport(15, 25, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPriority = createTestHealthReport(15, 45, Priority.LOW, 10, 20, 30);

assertThat(reportHighPriority.getScore()).isEqualTo(0);
assertThat(reportNormalPriority.getScore()).isEqualTo(0);
assertThat(reportLowPriority.getScore()).isEqualTo(0);
}

/**
* Test whether the health descriptor is disabled.
*/
@Test
void testDisabledHealthDescriptor() {
void shouldBeNullForDisabledHealthDescriptor() {
HealthReport report = createTestHealthReport(0, 0, Priority.NORMAL, 10, 20, 30);

assertThat(report).isNull();
Expand All @@ -79,69 +77,77 @@ void testDisabledHealthDescriptor() {
* Tests whether we evaluate correctly to a 100% health if healthy threshold fits the priority issue number.
*/
@Test
void testHealthBoundary () {
HealthReport reportHighPrio = createTestHealthReport(10, 15, Priority.HIGH,10, 20, 30);
HealthReport reportNormalPrio = createTestHealthReport(30, 35, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPrio = createTestHealthReport(60, 65, Priority.LOW, 10, 20, 30);

assertThat(reportHighPrio.getScore()).isEqualTo(100);
assertThat(reportNormalPrio.getScore()).isEqualTo(100);
assertThat(reportLowPrio.getScore()).isEqualTo(100);
void shouldTestHealthBoundary() {
HealthReport reportHighPriority = createTestHealthReport(10, 15, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPriority = createTestHealthReport(30, 35, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPriority = createTestHealthReport(60, 65, Priority.LOW, 10, 20, 30);

assertThat(reportHighPriority.getScore()).isEqualTo(100);
assertThat(reportNormalPriority.getScore()).isEqualTo(100);
assertThat(reportLowPriority.getScore()).isEqualTo(100);
}

/**
* Tests whether we evaluate correctly to a 0% health if unhealthy threshold fits the priority issue number.
*/
@Test
void testUnHealthBoundary () {
HealthReport reportHighPrio = createTestHealthReport(4, 10, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPrio = createTestHealthReport(15, 30, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPrio = createTestHealthReport(15, 60, Priority.LOW, 10, 20, 30);

assertThat(reportHighPrio.getScore()).isEqualTo(0);
assertThat(reportNormalPrio.getScore()).isEqualTo(0);
assertThat(reportLowPrio.getScore()).isEqualTo(0);
void shouldTestUnHealthBoundary() {
HealthReport reportHighPriority = createTestHealthReport(4, 10, Priority.HIGH, 10, 20, 30);
HealthReport reportNormalPriority = createTestHealthReport(15, 30, Priority.NORMAL, 10, 20, 30);
HealthReport reportLowPriority = createTestHealthReport(15, 60, Priority.LOW, 10, 20, 30);

assertThat(reportHighPriority.getScore()).isEqualTo(0);
assertThat(reportNormalPriority.getScore()).isEqualTo(0);
assertThat(reportLowPriority.getScore()).isEqualTo(0);
}

/**
* Tests the correct description for no items.
*/
@Test
void testDescriptionNoItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 0,0,0);
void shouldReturnDescriptionForNoItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 0, 0, 0);
assertThat(report.getDescription()).isEqualTo(DESCRIPTION_MESSAGE + "no" + DESCRIPTION_MESSAGE_ENDING_PLURAL);
}

/**
* Tests the correct description for a single item.
*/
@Test
void testDescriptionSingleItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 1,0,0);
void shouldReturnDescriptionForSingleItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 1, 0, 0);
assertThat(report.getDescription()).isEqualTo(DESCRIPTION_MESSAGE + "1" + DESCRIPTION_MESSAGE_ENDING_SINGULAR);
}

/**
* Tests the correct description for multiple items.
*/
@Test
void testDescriptionMultipleItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 10,30,60);
void shouldReturnDescriptionForMultipleItem() {
HealthReport report = createTestHealthReport(4, 10, Priority.HIGH, 10, 30, 60);
assertThat(report.getDescription()).isEqualTo(DESCRIPTION_MESSAGE + "10" + DESCRIPTION_MESSAGE_ENDING_PLURAL);
}

/**
* Creates the {@link HealthReport} under test with specified parameters.
*
* @param healthyThreshold
* the healthy threshold, i.e. when health is reported as 100%.
* the healthy threshold, i.e. when health is reported as 100%.
* @param unhealthyThreshold
* the unhealthy threshold, i.e. when health is reported as 0%.
* the unhealthy threshold, i.e. when health is reported as 0%.
* @param priority
* the minimum priority that should be considered when computing build health
* the minimum priority that should be considered when computing build health
* @param highSize
* the threshold for priority high
* @param normalSize
* the threshold for priority normal
* @param lowSize
* the threshold for priority low
*
* @return the {@link HealthReport} under test
*/
private HealthReport createTestHealthReport(int healthyThreshold, int unhealthyThreshold, Priority priority,
int highSize, int normalSize, int lowSize) {
int highSize, int normalSize, int lowSize) {
HealthDescriptor healthDescriptor = new HealthDescriptor(healthyThreshold, unhealthyThreshold, priority);
HealthReportBuilder builder = new HealthReportBuilder(healthDescriptor);

Expand Down

0 comments on commit 80e06c3

Please sign in to comment.