Java Extreme Programming Cookbook phần 6

Điều này có vẻ ngớ ngẩn, nhưng suy nghĩ lại về các dự án cuối cùng bạn làm việc trên rất nhiều các sơ đồ được tạo ra. Khi bạn gặp phải một lỗi trong ứng dụng, bạn thường chuyển sang sơ đồ đầu tiên, | return true public int getRow throws SQLException return 1 MockResultSet mockRs new MyMockResultSet 1 1 MockPreparedStatement mockPs new MockPreparedStatement 1 0001 1 mockRs MockConnection mockConnection new MockConnection mockPs 0 AccountFactory acctFact new AccountFactory call the method that we are actually testing Account acct 0001 mockConnection MyMockResultSet is the key to this test. It extends MockResultSetJdk14 described shortly . MyMockResultSet overrides a handful of abstract methods in order to simulate data that would normally be returned from a true database call. Our goal is to support our unit tests without relying on a real database and we only need to stub out the actual methods that our test calls. The remainder of the unit test should look familiar if you read through the recipes presented earlier in this chapter. Specifically we tell the mock result set how many calls to expect. We then create and set up the mock prepared statement and connection using them to exercise the code in AccountFactory. When finished we ask each of the mock objects to verify themselves. It turns out that the version of Mock Objects used in this chapter does not fully support J2SE . Specifically many new JDBC methods are not defined in the MockResultSet class. For this reason we created MockResultSetJdk14 as shown in Example 6-10. This class merely provides dummy implementations of the new JDBC methods so our examples compile under J2SE . Example 6-10. Making MockResultSet work with J2SE package import import import . public abstract class MockResultSetJdk14 extends MockResultSet public URL getURL int .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.