From the course: JSON Processing with Java EE

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a model from a JSON string

Create a model from a JSON string

From the course: JSON Processing with Java EE

Start my 1-month free trial

Create a model from a JSON string

- [Instructor] Let's open up the ObjectExample1 test class and start writing the test. Here we are using the arrange act assert test pattern, as it makes a very clear separation between the test setup and the code we're actually trying to test. Also, I've decided that I'm going to use the test framework called AssertJ. This is because it's a very fluent and intuitive API. Okay, so let's get started. The first thing I want to do is to assert that each element of the JSON document has been appropriately interpreted and loaded into the JSON object. Let's get started with the first property, which is the title property. I'm gonna start with my assertThat statement and then I'm going to call the jsonObject instance. On the jsonObject I want to get the first property which is a string property, and this string property is called title. Once I've got the title property, I call in the getString method on the jsonObject. I can do a simple isEqualTo and parse in the value that I expect it to…

Contents