In these example, the variable “em” is an entity manger initialized just like it was in the first tutorial.
Empty String
Setup: None required
Unknown Class
Setup: None required
Minimal “Get All”
Setup: None required
Successfully Get a Single Object
Setup: Insert exactly 1 Person entity in the database
Unsuccessfully Try to get a Single Object When There Are None
Setup: Make sure there are no Person entities in the database
Unsuccessfully Try to get a Single Object With Too Many
Setup: Insert two or more Person entities in the database
Find By Primary Key
Setup: Insert a Person in the database, make sure to get the key of the object inserted
Unsuccessfully Find by Primary Key
Setup: None required
Search Using Query Parameter and Storing Result as List<?>
Setup: Insert one person record where the Person’s first name = “Brett”.
Search Using Query Parameter and Storing Result as List
Setup: Insert one person record where the Person’s first name = “Brett”.
Do Find by Primary Key and Queries Return == Objects
Setup: Insert one person record and store the primary key. Also make sure the first name of the person equals “Brett”.
Use Wrong Class Name
Setup: None required
Use Wrong Field Name
Setup: None required
Use Column Name Instead of Field Name
Setup: None required, but maybe insert a single person whose first name = “Brett”.
Use a Parameter but Provide Wrong Index
Setup: None required
Set Parameter Where There are None: Version 1
Setup: None required
Set Parameter When There Are None: Version 2
Setup: None required
title: Tutorial_2_The_First_Example
—
Test Setup
We have a bit of setup/initialization code we need to do before we can get started. We have seen all of this code before in Tutorial 1. The difference here is that we are going to work though some refactorings to get to where we were in tutorial 1. Here are the various parts:
Configure the Logger
Create the Entity Manager Factory
Create the Entity Manager
Create Entities
Use the Entity Manager
Perform a Query and Verify it Works
The Whole Thing
Here’s all of this put together. Note that we’re going to refactor this heavily coming up.
Get it Running
After creating your Test Class, verify that it runs and that this test passes:
Comments