> For the complete documentation index, see [llms.txt](https://ysfang82.gitbook.io/development-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ysfang82.gitbook.io/development-notes/programming-langauges/java/implementation-and-testing.md).

# Implementation & Testing

Frequently used libs

* [Guava](https://github.com/google/guava) ([User guide](https://github.com/google/guava/wiki))
* [Gson](https://github.com/google/gson)
* [jackson-dataformat-yaml](https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml)
* [commons-io](https://commons.apache.org/proper/commons-io/description.html)

Mocking Snippets

* Turning a JSON resource into an object list
  * libs: Gson, Guava, commons-io

```
  public static ImmutableList<Person> getPeople() throws IOException {
    InputStream inputStream = Resources.getResource("people.json").openStream();
    String json = IOUtils.toString(inputStream);
    Type listType = new TypeToken<ArrayList<Person>>() {
    }.getType();
    List<Person> people = new Gson().fromJson(json, listType);
    return ImmutableList.copyOf(people);
  }
```

* Turning a YAML resource into an object list
  * lib: jackson-dataformat-yaml, Guava, commons-io
  * For POJO to work with `ObjectMapper`, either below is needed:
    * A default constructor
    * Using `@JsonCreator`, `@JsonProperty` for constructor and its arguments

```
public static ImmutableList<Person> getPeopleByYml() throws IOException {
  InputStream inputStream = Resources.getResource("people.yml").openStream();
  ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
  List<Person> people = mapper.readValue(inputStream, new TypeReference<List<Person>>(){});
  return ImmutableList.copyOf(people);
}
```

�
