O'Reilly logo

Extreme Programming Installed by Chet Hendrickson, Ann Anderson, Ron Jeffries

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adapter Implementation

Let's write the button code as if a ResultTableAdapter class existed:

findButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Query q = new Query(queryField.getText());
      resultTable.setModel(
          new ResultTableAdapter(getSearcher().find(q)));
      }
  });

When this fails to compile, stub out a dummy implementation:

  public class ResultTableAdapter extends DefaultTableModel {
      public ResultTableAdapter(Result r) {}
  }
  

Test0() still passes, and test1() still fails.

The adapter is straightforward to write, but we begin by writing a test.

 public void testResultTableAdapter() { Result result = new TestResult(2); ResultTableAdapter rta = new ResultTableAdapter(result); assertEquals("Author", rta.getColumnName(0)); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required