Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-29059: Display cron run times after warnings if warnings occur.
- Loading branch information
1 parent
cf62704
commit cbf46fc
Showing
3 changed files
with
276 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package hudson.util; | ||
|
||
/** | ||
* A class used to contain types of string response. Extra messages and warnings | ||
* can be appended to the class until a response is required. | ||
* The purpose of this class is to allow methods to update the message or | ||
* warning response without needing to return the entire response, allowing more | ||
* complex responses to be constructed. | ||
*/ | ||
public class ResponseObject { | ||
private final String message; | ||
private final String warning; | ||
|
||
public ResponseObject() { | ||
message = ""; | ||
warning = ""; | ||
} | ||
|
||
public ResponseObject(String message, String warning) { | ||
this.message = message; | ||
this.warning = warning; | ||
} | ||
|
||
public boolean hasMessage() { | ||
return !message.isEmpty(); | ||
} | ||
|
||
public boolean hasWarning() { | ||
return !warning.isEmpty(); | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public String getWarning() { | ||
return warning; | ||
} | ||
|
||
public String getWarningAndMessge() { | ||
if (hasWarning() && hasMessage()) { | ||
return warning + "; " + message; | ||
} else { | ||
return warning + message; | ||
} | ||
} | ||
|
||
public ResponseObject withExtraMessage(String message) { | ||
String updatedMessage; | ||
if (this.hasMessage()) { | ||
updatedMessage = this.message + "; " + message; | ||
} else { | ||
updatedMessage = message; | ||
} | ||
return new ResponseObject(updatedMessage, warning); | ||
} | ||
|
||
public ResponseObject withExtraWarning(String warning) { | ||
String updatedWarning; | ||
if (this.hasWarning()) { | ||
updatedWarning = this.warning + "; " + warning; | ||
} else { | ||
updatedWarning = warning; | ||
} | ||
return new ResponseObject(message, updatedWarning); | ||
} | ||
} |
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,182 @@ | ||
package hudson.util; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class ResponseObjectTest { | ||
|
||
@Test | ||
public void emptyMessageReportsAsEmpty() throws Exception { | ||
// given | ||
ResponseObject response = new ResponseObject(); | ||
|
||
// when | ||
boolean hasMessage = response.hasMessage(); | ||
|
||
// then | ||
assertFalse(hasMessage); | ||
} | ||
|
||
@Test | ||
public void emptyWarningReportsAsEmpty() throws Exception { | ||
// given | ||
ResponseObject response = new ResponseObject(); | ||
|
||
// when | ||
boolean hasWarning = response.hasWarning(); | ||
|
||
// then | ||
assertFalse(hasWarning); | ||
} | ||
|
||
@Test | ||
public void nonEmptyMessageReportsAsNonEmpty() throws Exception { | ||
// given | ||
ResponseObject response = new ResponseObject("test", ""); | ||
|
||
// when | ||
boolean hasMessage = response.hasMessage(); | ||
|
||
// then | ||
assertTrue(hasMessage); | ||
} | ||
|
||
@Test | ||
public void nonEmptWarningReportsAsNonEmpty() throws Exception { | ||
// given | ||
ResponseObject response = new ResponseObject("", "test"); | ||
|
||
// when | ||
boolean hasWarning = response.hasWarning(); | ||
|
||
// then | ||
assertTrue(hasWarning); | ||
} | ||
|
||
@Test | ||
public void messageIsReturned() throws Exception { | ||
// given | ||
String expected = "test123"; | ||
ResponseObject response = new ResponseObject(expected, ""); | ||
|
||
// when | ||
String actual = response.getMessage(); | ||
|
||
// then | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void warningIsReturned() throws Exception { | ||
// given | ||
String expected = "test123"; | ||
ResponseObject response = new ResponseObject("", expected); | ||
|
||
// when | ||
String actual = response.getWarning(); | ||
|
||
// then | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void emptyMessageIsUpdatedCorrectly() throws Exception { | ||
// given | ||
String expected = "test123"; | ||
ResponseObject response = new ResponseObject(); | ||
|
||
// when | ||
ResponseObject newResponse = response.withExtraMessage(expected); | ||
String actual = newResponse.getMessage(); | ||
|
||
// then | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void emptyWarningIsUpdatedCorrectly() throws Exception { | ||
// given | ||
String expected = "test123"; | ||
ResponseObject response = new ResponseObject(); | ||
|
||
// when | ||
ResponseObject newResponse = response.withExtraWarning(expected); | ||
String actual = newResponse.getWarning(); | ||
|
||
// then | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void nonEmptyMessageIsUpdatedCorrectly() throws Exception { | ||
// given | ||
String extra = "123"; | ||
String initial = "test"; | ||
ResponseObject response = new ResponseObject(initial, ""); | ||
|
||
// when | ||
ResponseObject newResponse = response.withExtraMessage(extra); | ||
String actual = newResponse.getMessage(); | ||
|
||
// then | ||
String expected = initial + "; " + extra; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void nonEmptyWarningIsUpdatedCorrectly() throws Exception { | ||
// given | ||
String extra = "123"; | ||
String initial = "test"; | ||
ResponseObject response = new ResponseObject("", initial); | ||
|
||
// when | ||
ResponseObject newResponse = response.withExtraWarning(extra); | ||
String actual = newResponse.getWarning(); | ||
|
||
// then | ||
String expected = initial + "; " + extra; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void warningAndMessageAreSeparated() throws Exception { | ||
// given | ||
String warning = "warning"; | ||
String message = "message"; | ||
ResponseObject response = new ResponseObject(message, warning); | ||
|
||
// when | ||
String actual = response.getWarningAndMessge(); | ||
|
||
// then | ||
String expected = warning + "; " + message; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void onlyWarningNotSeparated() throws Exception { | ||
// given | ||
String warning = "warning"; | ||
ResponseObject response = new ResponseObject("", warning); | ||
|
||
// when | ||
String actual = response.getWarningAndMessge(); | ||
|
||
// then | ||
assertEquals(warning, actual); | ||
} | ||
|
||
@Test | ||
public void onlyMessageNotSeparated() throws Exception { | ||
// given | ||
String message = "message"; | ||
ResponseObject response = new ResponseObject(message, ""); | ||
|
||
// when | ||
String actual = response.getWarningAndMessge(); | ||
|
||
// then | ||
assertEquals(message, actual); | ||
} | ||
} |