Build Operate Check – Acceptance Pattern

Build operate Check is one of the acceptance pattern. So its good that to follow this pattern while creating the Junit test cases.

The first step is to build the input data and hold it in memory, then execute it on the actual code which means call/invoke the code to operate on that data. Finally check the results of that operation.

Please refer the below example.

package com.dao.test;

import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import com.dao.ContactDAO;
import com.model.Contact;

public class ContactDAOTest{
    public void testCreateContactData() throws Exception {
        //Build the test data
        Contact contact = buildContactData("bala","dublin");
        //Call the ContactDAO to create the contact information. Assume that 
        //Create() returns an id after the successful creation of the contact in DB
        String id = new ContactDAO().create(contact);
        //check the id and make sure that its not null/blank

    private Contact buildContactData(String name, String city) {
        Contact contact = new Contact();
        return contact;

package com.model;
public static class Contact {

        private String id;
        private String name;
        private String city;

        public String getId() {
            return id;

        public void setId(String id) {
   = id;

        public String getName() {
            return name;

        public void setName(String name) {
   = name;

        public String getCity() {
            return city;

        public void setCity(String city) {
   = city;


Post Redirect Get Pattern

This is one of the web design pattern which is used to prevent the double form submission issue.

In the old days, when we design an application with JSP’s, we often face double form submission issue. So one of the best way to avoid this to disable the submit button as soon as the submit button is clicked. But if we show the result on same JSP page, then if the user refreshes the browser, then the form will be submitted again which cause some undesirable issues.

To avoid these kinds of errors/issues, we may need to change the API/server code to validate the request and some custom states. So it requires some unnecessary state maintenance in the server side.

Post Redirect Get pattern comes to the rescue in this kind of situation. Please refer the below diagram.



Here in this case, As soon as the user submits the form, the server does the operation on the backend and also forces the browser to redirect to a confirmation page. So if the user refreshes the confirmation page, then it would not have any impact as it will not do any operation other than showing the confirmation page.

But we have to keep in the below points along with this pattern.

  1. Disable the Submit button as soon as the user clicks on it
  2. If the server takes long time to respond back with the confirmation page and user tries to stop the browser and refresh the page in the mean time, then it will cause some other issues. So to handle these kind of issues, we have to either maintain some state and by checking this we can prevent the double submission issues.