-2

I want to write a test case for the given method

private String productCode;

public PaymentManager() {
    this.productCode = "SMART-TV;
}

@Override
public boolean isResponsibleFor(TransactionDetailResource resource) {
    return productCode.equals(resource.getProductCode());
}

How to write test case for this method

Milan Paudyal
  • 519
  • 9
  • 11

1 Answers1

1

First, create a test class and a test function

@Test
public void testIsResponsibleFor() {
...
}

(If you are using Eclipse, you can press Ctrl+J, It will automatically create the test class for you)

Then in your test function you must create your two objects, one PaymentManager and one TransactionDetailResource.

PaymentManager p = PaymentManager();
TransactionDetailResource t = TransactionDetailResource();
t.setProductCode("SMART-TV")

I have assumed you got a Setter in your TransactionDetailResource class.

AssertThat(p.isResponsibleFor(t),is(Boolean.True))

This is a partial answer but It can gives you a starting point

rilent
  • 659
  • 1
  • 6
  • 22