// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// @Nonnull
// public static BigDecimal amountWithAdjustments(@Nonnull InvoiceItem item,
//         @Nonnull Multimap<UUID, InvoiceItem> allAdjustments) {
//     Iterable<InvoiceItem> adjustments = allAdjustments.get(item.getId());
//     BigDecimal amount = sumItems(adjustments);
//     if (item.getAmount() != null) {
//         amount = amount.add(item.getAmount());
//     }
//     return amount;
// }
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// public static BigDecimal sumAmounts(Iterable<BigDecimal> amounts) {
//     BigDecimal sum = ZERO;
//     for (BigDecimal amount : amounts) {
//         sum = sum.add(amount);
//     }
//     return sum;
// }
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// @Nonnull
// public static BigDecimal sumItems(@Nullable Iterable<InvoiceItem> invoiceItems) {
//     if (invoiceItems == null) {
//         return ZERO;
//     }
//     BigDecimal sum = ZERO;
//     for (InvoiceItem item : invoiceItems) {
//         if (item.getAmount() != null) {
//             sum = sum.add(item.getAmount());
//         }
//     }
//     return sum;
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/TestUtil.java
// public static void assertEqualsIgnoreScale(BigDecimal actual, BigDecimal expected) {
//     assertTrue(expected.compareTo(actual) == 0);
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/InvoiceItemBuilder.java
// @SuppressWarnings("javadoc")
// public class InvoiceItemBuilder implements Builder<InvoiceItem> {
//     private Invoice invoice;
//     private InvoiceItemType type;
//     private LocalDate startDate, endDate;
//     private BigDecimal amount;
//     private String planName;
//     private Promise<InvoiceItem> linkedItem;
// 
//     private Promise<InvoiceItem> builtItemHolder;
// 
//     public static InvoiceItemBuilder item() {
//         return new InvoiceItemBuilder();
//     }
// 
//     @Override
//     public InvoiceItem build() {
//         UUID id = randomUUID();
//         UUID invoiceId = invoice == null ? null : invoice.getId();
//         UUID accountId = invoice == null ? null : invoice.getAccountId();
//         String description = type == null ? null : "Test " + type.name();
//         UUID linkedItemId = linkedItem == null ? null : linkedItem.get().getId();
//         PluginInvoiceItem item = new PluginInvoiceItem(id, type, invoiceId, accountId, startDate, endDate, amount, EUR,
//                 description, null, null, planName, null, null, linkedItemId, null, null, null);
//         if (builtItemHolder != null) {
//             builtItemHolder.resolve(item);
//         }
//         return item;
//     }
// 
//     public InvoiceItemBuilder withInvoice(Invoice invoice) {
//         this.invoice = invoice;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withType(InvoiceItemType type) {
//         this.type = type;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withStartDate(LocalDate startDate) {
//         this.startDate = startDate;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withEndDate(LocalDate endDate) {
//         this.endDate = endDate;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withAmount(BigDecimal amount) {
//         this.amount = amount;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withPlanName(String planName) {
//         this.planName = planName;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withLinkedItem(Promise<InvoiceItem> linkedItem) {
//         this.linkedItem = linkedItem;
//         return this;
//     }
// 
//     public InvoiceItemBuilder thenSaveTo(Promise<InvoiceItem> itemHolder) {
//         builtItemHolder = itemHolder;
//         return this;
//     }
// }


import static com.google.common.collect.Lists.newArrayList;
import static java.math.BigDecimal.ONE;
import static java.math.BigDecimal.TEN;
import static java.math.BigDecimal.ZERO;
import static java.math.BigDecimal.valueOf;
import static java.util.Arrays.asList;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.amountWithAdjustments;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.sumAmounts;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.sumItems;
import static org.killbill.billing.test.helpers.TestUtil.assertEqualsIgnoreScale;
import java.math.BigDecimal;
import java.util.UUID;
import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.test.helpers.InvoiceItemBuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
/*
 * Copyright 2015 Benjamin Gandon
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.killbill.billing.plugin.simpletax.util;





/**
 * Tests for {@link InvoiceHelpers}.
 *
 * @author Benjamin Gandon
 */
@SuppressWarnings("javadoc")
public class TestInvoiceHelpers {

    private static final BigDecimal NINE = valueOf(9L);
    private static final BigDecimal ELEVEN = valueOf(11L);
    private static final BigDecimal EIGHTTEEN = valueOf(18L);

    private InvoiceItem itemA, itemB, itemC, itemD;

    @BeforeClass
    public void init() {
// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// @Nonnull
// public static BigDecimal amountWithAdjustments(@Nonnull InvoiceItem item,
//         @Nonnull Multimap<UUID, InvoiceItem> allAdjustments) {
//     Iterable<InvoiceItem> adjustments = allAdjustments.get(item.getId());
//     BigDecimal amount = sumItems(adjustments);
//     if (item.getAmount() != null) {
//         amount = amount.add(item.getAmount());
//     }
//     return amount;
// }
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// public static BigDecimal sumAmounts(Iterable<BigDecimal> amounts) {
//     BigDecimal sum = ZERO;
//     for (BigDecimal amount : amounts) {
//         sum = sum.add(amount);
//     }
//     return sum;
// }
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/util/InvoiceHelpers.java
// @Nonnull
// public static BigDecimal sumItems(@Nullable Iterable<InvoiceItem> invoiceItems) {
//     if (invoiceItems == null) {
//         return ZERO;
//     }
//     BigDecimal sum = ZERO;
//     for (InvoiceItem item : invoiceItems) {
//         if (item.getAmount() != null) {
//             sum = sum.add(item.getAmount());
//         }
//     }
//     return sum;
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/TestUtil.java
// public static void assertEqualsIgnoreScale(BigDecimal actual, BigDecimal expected) {
//     assertTrue(expected.compareTo(actual) == 0);
// }
// 
// Path: src/test/java/org/killbill/billing/test/helpers/InvoiceItemBuilder.java
// @SuppressWarnings("javadoc")
// public class InvoiceItemBuilder implements Builder<InvoiceItem> {
//     private Invoice invoice;
//     private InvoiceItemType type;
//     private LocalDate startDate, endDate;
//     private BigDecimal amount;
//     private String planName;
//     private Promise<InvoiceItem> linkedItem;
// 
//     private Promise<InvoiceItem> builtItemHolder;
// 
//     public static InvoiceItemBuilder item() {
//         return new InvoiceItemBuilder();
//     }
// 
//     @Override
//     public InvoiceItem build() {
//         UUID id = randomUUID();
//         UUID invoiceId = invoice == null ? null : invoice.getId();
//         UUID accountId = invoice == null ? null : invoice.getAccountId();
//         String description = type == null ? null : "Test " + type.name();
//         UUID linkedItemId = linkedItem == null ? null : linkedItem.get().getId();
//         PluginInvoiceItem item = new PluginInvoiceItem(id, type, invoiceId, accountId, startDate, endDate, amount, EUR,
//                 description, null, null, planName, null, null, linkedItemId, null, null, null);
//         if (builtItemHolder != null) {
//             builtItemHolder.resolve(item);
//         }
//         return item;
//     }
// 
//     public InvoiceItemBuilder withInvoice(Invoice invoice) {
//         this.invoice = invoice;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withType(InvoiceItemType type) {
//         this.type = type;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withStartDate(LocalDate startDate) {
//         this.startDate = startDate;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withEndDate(LocalDate endDate) {
//         this.endDate = endDate;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withAmount(BigDecimal amount) {
//         this.amount = amount;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withPlanName(String planName) {
//         this.planName = planName;
//         return this;
//     }
// 
//     public InvoiceItemBuilder withLinkedItem(Promise<InvoiceItem> linkedItem) {
//         this.linkedItem = linkedItem;
//         return this;
//     }
// 
//     public InvoiceItemBuilder thenSaveTo(Promise<InvoiceItem> itemHolder) {
//         builtItemHolder = itemHolder;
//         return this;
//     }
// }


// Path: src/test/java/org/killbill/billing/plugin/simpletax/util/TestInvoiceHelpers.java
import static com.google.common.collect.Lists.newArrayList;
import static java.math.BigDecimal.ONE;
import static java.math.BigDecimal.TEN;
import static java.math.BigDecimal.ZERO;
import static java.math.BigDecimal.valueOf;
import static java.util.Arrays.asList;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.amountWithAdjustments;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.sumAmounts;
import static org.killbill.billing.plugin.simpletax.util.InvoiceHelpers.sumItems;
import static org.killbill.billing.test.helpers.TestUtil.assertEqualsIgnoreScale;
import java.math.BigDecimal;
import java.util.UUID;
import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.test.helpers.InvoiceItemBuilder;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;

/*
 * Copyright 2015 Benjamin Gandon
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.killbill.billing.plugin.simpletax.util;





/**
 * Tests for {@link InvoiceHelpers}.
 *
 * @author Benjamin Gandon
 */
@SuppressWarnings("javadoc")
public class TestInvoiceHelpers {

    private static final BigDecimal NINE = valueOf(9L);
    private static final BigDecimal ELEVEN = valueOf(11L);
    private static final BigDecimal EIGHTTEEN = valueOf(18L);

    private InvoiceItem itemA, itemB, itemC, itemD;

    @BeforeClass
    public void init() {
        itemA = new InvoiceItemBuilder()//