-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise vacation stategy to capture stack trace (#217)
- Loading branch information
Showing
6 changed files
with
100 additions
and
60 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
42 changes: 4 additions & 38 deletions
42
src/main/java/com/nordstrom/automation/selenium/exceptions/ContainerVacatedException.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,48 +1,14 @@ | ||
package com.nordstrom.automation.selenium.exceptions; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.nordstrom.automation.selenium.utility.ReflectUtil; | ||
|
||
/** | ||
* This exception is thrown when a client calls a method of a container object that's no longer valid. | ||
*/ | ||
public class ContainerVacatedException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 2043877560841903084L; | ||
|
||
private final transient Method vacater; | ||
private static final String PREAMBLE = "Container object was vacated by invocation of method: "; | ||
|
||
/** | ||
* Constructs a new {@code container vacated} exception with the specified vacater. | ||
* | ||
* @param vacater method that caused the container to be vacated | ||
*/ | ||
public ContainerVacatedException(final Method vacater) { | ||
super(getMessage(vacater)); | ||
this.vacater = vacater; | ||
} | ||
private static final long serialVersionUID = -7653982501901130765L; | ||
|
||
/** | ||
* Get the method that caused the affected container object to be vacated. | ||
* | ||
* @return method that vacated the target object | ||
*/ | ||
public Method getVacater() { | ||
return vacater; | ||
public ContainerVacatedException(VacationStackTrace stackTrace) { | ||
super(stackTrace); | ||
} | ||
|
||
/** | ||
* Assemble the message for this exception. | ||
* | ||
* @param method method that vacated the target object. | ||
* @return message for this exception | ||
*/ | ||
private static String getMessage(final Method method) { | ||
String className = method.getDeclaringClass().getSimpleName(); | ||
String signature = ReflectUtil.getSignature(method); | ||
return PREAMBLE + className + ":" + signature; | ||
} | ||
|
||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/nordstrom/automation/selenium/exceptions/VacationStackTrace.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.nordstrom.automation.selenium.exceptions; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import com.nordstrom.automation.selenium.utility.ReflectUtil; | ||
import com.nordstrom.common.base.StackTrace; | ||
|
||
public class VacationStackTrace extends StackTrace { | ||
|
||
private static final long serialVersionUID = -512001372372827847L; | ||
|
||
private final transient Method vacater; | ||
private final transient String reason; | ||
private static final String PREAMBLE = "Container object was vacated by invocation of method: "; | ||
|
||
/** | ||
* Constructs a new {@code container vacated} exception with the specified vacater. | ||
* | ||
* @param vacater method that caused the container to be vacated | ||
*/ | ||
public VacationStackTrace(final Method vacater) { | ||
this(vacater, null); | ||
} | ||
|
||
/** | ||
* Constructs a new {@code container vacated} exception with the specified vacater. | ||
* | ||
* @param vacater method that caused the container to be vacated | ||
* @param reason for vacating the target object | ||
*/ | ||
public VacationStackTrace(final Method vacater, final String reason) { | ||
super(getMessage(vacater, reason)); | ||
this.vacater = vacater; | ||
this.reason = reason; | ||
} | ||
|
||
/** | ||
* Get the reason that the affected container object to be vacated. | ||
* | ||
* @return reason for vacating the target object | ||
*/ | ||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
/** | ||
* Get the method that caused the affected container object to be vacated. | ||
* | ||
* @return method that vacated the target object | ||
*/ | ||
public Method getVacater() { | ||
return vacater; | ||
} | ||
|
||
/** | ||
* Assemble the message for this exception. | ||
* | ||
* @param method method that vacated the target object. | ||
* @param reason for vacating the target object | ||
* @return message for this exception | ||
*/ | ||
private static String getMessage(final Method method, final String reason) { | ||
String className = method.getDeclaringClass().getSimpleName(); | ||
String signature = ReflectUtil.getSignature(method); | ||
String suffix = (reason != null) ? "\n" + reason : ""; | ||
return PREAMBLE + className + ":" + signature + suffix; | ||
} | ||
|
||
} |
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