### Question:
TransactionService { public static Transaction create(final Context context, final Transaction transaction) throws NetLicensingException { CheckUtils.paramNotNull(transaction, "transaction"); return NetLicensingService.getInstance().post(context, Constants.Transaction.ENDPOINT_PATH, transaction.asRequestForm(), Transaction.class); }  static Transaction create(final Context context, final Transaction transaction); static Transaction get(final Context context, final String number); static Page<Transaction> list(final Context context, final String filter); static Transaction update(final Context context, final String number, final Transaction transaction);  }### Answer:
@Test public void testCreate() throws Exception { final Transaction newTransaction = new TransactionImpl(); newTransaction.setSource(TransactionSource.AUTO_LICENSE_CREATE); newTransaction.setStatus(TransactionStatus.CLOSED); newTransaction.setNumber("TR001TEST"); newTransaction.setActive(false); newTransaction.setCurrency(Currency.EUR); newTransaction.setGrandTotal(new BigDecimal("100")); newTransaction.setDiscount(new BigDecimal("5")); newTransaction.addProperty(TRANSACTION_CUSTOM_PROPERTY, "Custom property value"); final Transaction createdTransaction = TransactionService.create(context, newTransaction); assertNotNull(createdTransaction); assertEquals(TransactionSource.AUTO_LICENSE_CREATE, createdTransaction.getSource()); assertEquals(TransactionStatus.CLOSED, createdTransaction.getStatus()); assertEquals("TR001TEST", createdTransaction.getNumber()); assertEquals(false, createdTransaction.getActive()); assertEquals(Currency.EUR, createdTransaction.getCurrency()); assertEquals(new BigDecimal("100.00"), createdTransaction.getGrandTotal()); assertEquals(new BigDecimal("5.00"), createdTransaction.getDiscount()); assertEquals("Custom property value", createdTransaction.getProperties().get(TRANSACTION_CUSTOM_PROPERTY)); }
@Test public void testCreateEmpty() throws Exception { thrown.expect(RestException.class); final Transaction newTransaction = new TransactionImpl(); TransactionService.create(context, newTransaction); }
@Test public void testCreateWithRequiredPropertiesOnly() throws Exception { final Transaction newTransaction = new TransactionImpl(); newTransaction.setSource(TransactionSource.SHOP); newTransaction.setStatus(TransactionStatus.PENDING); final Transaction createdTransaction = TransactionService.create(context, newTransaction); assertNotNull(createdTransaction); assertEquals(true, createdTransaction.getActive()); }
@Test public void testCreateWithGrandTotalAndDiscountAndWithoutCurrency() throws Exception { final Transaction newTransaction = new TransactionImpl(); newTransaction.setSource(TransactionSource.SHOP); newTransaction.setStatus(TransactionStatus.PENDING); newTransaction.setGrandTotal(new BigDecimal("80")); newTransaction.setDiscount(new BigDecimal("4")); thrown.expect(RestException.class); TransactionService.create(context, newTransaction); }
@Test public void testCreateWithGrandTotalAndCurrencyAndWithoutDiscount() throws Exception { final Transaction newTransaction = new TransactionImpl(); newTransaction.setSource(TransactionSource.SHOP); newTransaction.setStatus(TransactionStatus.PENDING); newTransaction.setGrandTotal(new BigDecimal("80")); newTransaction.setCurrency(Currency.EUR); thrown.expect(RestException.class); TransactionService.create(context, newTransaction); }