Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 5239dd1

Browse files
authored
Merge pull request #30 from sbtqa/fix/stash
Added check key not found
2 parents 400f0aa + c9e6f3a commit 5239dd1

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

datajack-api/src/main/java/ru/sbtqa/tag/datajack/Stash.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5+
import ru.sbtqa.tag.datajack.exceptions.StashKeyNotFoundException;
56

67
/**
78
* Temporary data storage. Put data to this storage as key-value pair to use it
@@ -56,6 +57,10 @@ public static void put(String key, Object value) {
5657
* @return an object found by specified key
5758
*/
5859
public static <T> T getValue(String key) {
60+
Map vault = getThreadVault();
61+
if (!vault.containsKey(key)) {
62+
throw new StashKeyNotFoundException(String.format("Key '%s' not found in stash", key));
63+
}
5964
return (T) getThreadVault().get(key);
6065
}
6166

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.sbtqa.tag.datajack.exceptions;
2+
3+
public class StashKeyNotFoundException extends RuntimeException {
4+
5+
public StashKeyNotFoundException(String message) {
6+
super(message);
7+
}
8+
9+
public StashKeyNotFoundException(String string, Throwable ex) {
10+
super(string, ex);
11+
}
12+
}

0 commit comments

Comments
 (0)