Skip to content

Commit d52a293

Browse files
committed
Update README to add Params information
1 parent 0868a47 commit d52a293

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,61 @@ The **PathUtils** `getNextPath` method provides a method to acquire the next fil
276276

277277
...
278278
```
279+
280+
## Params Interface
281+
282+
The **Params** interface defines concise methods for the creation of named parameters and parameter maps. This facility can make your code much easier to read and maintain. The following example, which is extracted from the **Params** unit test class, demonstrates a few basic features.
283+
284+
#### Params Example
285+
```
286+
package com.nordstrom.example;
287+
288+
import static com.nordstrom.common.params.Params.param;
289+
import static org.testng.Assert.assertEquals;
290+
import static org.testng.Assert.assertFalse;
291+
import static org.testng.Assert.assertTrue;
292+
293+
import java.util.Optional;
294+
import org.testng.annotations.Test;
295+
import com.nordstrom.common.params.Params;
296+
297+
public class ParamTest implements Params {
298+
299+
@Test
300+
public void testDefault() {
301+
assertFalse(Params.super.getParameters().isPresent());
302+
}
303+
304+
@Test
305+
public void testParam() {
306+
Param param = param("boolean", true);
307+
assertEquals(param.getKey(), "boolean");
308+
verifyBoolean(param.getVal());
309+
}
310+
311+
@Test
312+
public void testParams() {
313+
Optional<Map<String, Object>> optParameters = getParameters();
314+
assertTrue(optParameters.isPresent());
315+
Map<String, Object> parameters = optParameters.get();
316+
assertFalse(parameters.isEmpty());
317+
318+
assertTrue(parameters.containsKey("boolean"));
319+
verifyBoolean(parameters.get("boolean"));
320+
}
321+
322+
private void verifyBoolean(Object value) {
323+
assertTrue(value instanceof Boolean);
324+
assertTrue((Boolean) value);
325+
}
326+
327+
@Override
328+
public Optional<Map<String, Object>> getParameters() {
329+
return Params.mapOf(param("boolean", true), param("int", 1), param("String", "one"),
330+
param("Map", Params.mapOf(param("key", "value"))));
331+
}
332+
}
333+
334+
```
335+
336+
This code uses a static import to eliminate redundant references to the **Params** interface. It also shows the unrestricted data types of parameter values. The use of **Optional** objects enables you to provide an indication that no value was returned without the risks associated with `null`.

0 commit comments

Comments
 (0)