Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2013 Ning, Inc.
   *
   * Ning licenses this file to you 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 com.ning.billing.osgi.bundles.analytics.dao.factory;
 
 import java.util.UUID;
 
 
 
 
 
 
 
     @Override
     @BeforeMethod(groups = "fast")
     public void setUp() throws Exception {
         super.setUp();
 
         final OSGIKillbillDataSource osgiKillbillDataSource = Mockito.mock(OSGIKillbillDataSource.class);
 
         final DataSource dataSource = Mockito.mock(DataSource.class);
         Mockito.when(osgiKillbillDataSource.getDataSource()).thenReturn(dataSource);
 
         final OSGIKillbillLogService osgiKillbillLogService = Mockito.mock(OSGIKillbillLogService.class);
         Mockito.doAnswer(new Answer() {
             @Override
             public Object answer(final InvocationOnMock invocationthrows Throwable {
                 .info(Arrays.toString(invocation.getArguments()));
                 return null;
             }
         }).when(osgiKillbillLogService).log(Mockito.anyInt(), Mockito.anyString());
 
          = new BusinessInvoiceFactory(osgiKillbillLogServicenull, BusinessExecutor.newCachedThreadPool());
     }
 
     @Test(groups = "fast")
     public void testRevenueRecognizableClassicAccountCredit() throws Exception {
         final UUID invoiceId = UUID.randomUUID();
 
         // Classic account credit ($10), from the perspective of the CREDIT_ADJ item
         final BusinessInvoiceItemBaseModelDao businessCreditAdjItem = .createBusinessInvoiceItem(,
                                                                                                                ,
                                                                                                                createInvoiceItem(invoiceId.new BigDecimal("-10")),
                                                                                                                ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("10"))),
                                                                                                                null,
                                                                                                                null,
                                                                                                                null,
                                                                                                                ,
                                                                                                                ,
                                                                                                                ,
                                                                                                                ,
                                                                                                                );
         // We ignore these
         Assert.assertNull(businessCreditAdjItem);
 
         // Classic account credit ($10), from the perspective of the CBA_ADJ item
         final BusinessInvoiceItemBaseModelDao businessCreditItem = .createBusinessInvoiceItem(,
                                                                                                             ,
                                                                                                             createInvoiceItem(invoiceId.new BigDecimal("10")),
                                                                                                             ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("-10"))),
                                                                                                             null,
                                                                                                             null,
                                                                                                             null,
                                                                                                             ,
                                                                                                             ,
                                                                                                            ,
                                                                                                            ,
                                                                                                            );
        // We treat these as NOT recognizable account credits
        Assert.assertEquals(businessCreditItem.getAmount().compareTo(new BigDecimal("10")), 0);
        Assert.assertEquals(businessCreditItem.getItemType(), ..toString());
        Assert.assertEquals(businessCreditItem.getItemSource(), ..toString());
        // Invoice adjustment, not to be mixed with credits!
        final BusinessInvoiceItemBaseModelDao businessInvoiceAdjustmentItem = .createBusinessInvoiceItem(,
                                                                                                                       ,
                                                                                                                       createInvoiceItem(invoiceId.new BigDecimal("-10")),
                                                                                                                       ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("10"))),
                                                                                                                       null,
                                                                                                                       null,
                                                                                                                       null,
                                                                                                                       ,
                                                                                                                       ,
                                                                                                                       ,
                                                                                                                       ,
                                                                                                                       );
        Assert.assertEquals(businessInvoiceAdjustmentItem.getAmount().compareTo(new BigDecimal("-10")), 0);
        Assert.assertEquals(businessInvoiceAdjustmentItem.getItemType(), ..toString());
        Assert.assertEquals(businessInvoiceAdjustmentItem.getItemSource(), ..toString());
        // Invoice adjustment via refund
        final BusinessInvoiceItemBaseModelDao businessRefundInvoiceAdjustmentItem = .createBusinessInvoiceItem(,
                                                                                                                             ,
                                                                                                                             createInvoiceItem(invoiceId.new BigDecimal("-10")),
                                                                                                                             ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("10"))),
                                                                                                                             null,
                                                                                                                             null,
                                                                                                                             null,
                                                                                                                             ,
                                                                                                                             ,
                                                                                                                             ,
                                                                                                                             ,
                                                                                                                             );
        Assert.assertEquals(businessRefundInvoiceAdjustmentItem.getAmount().compareTo(new BigDecimal("-10")), 0);
        Assert.assertEquals(businessRefundInvoiceAdjustmentItem.getItemType(), ..toString());
        Assert.assertEquals(businessRefundInvoiceAdjustmentItem.getItemSource(), ..toString());
        // Item adjustment
        final BusinessInvoiceItemBaseModelDao businessInvoiceItemAdjustmentItem = .createBusinessInvoiceItem(,
                                                                                                                           ,
                                                                                                                           createInvoiceItem(invoiceId.new BigDecimal("-10")),
                                                                                                                           ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("10"))),
                                                                                                                           null,
                                                                                                                           null,
                                                                                                                           null,
                                                                                                                           ,
                                                                                                                           ,
                                                                                                                           ,
                                                                                                                           ,
                                                                                                                           );
        Assert.assertEquals(businessInvoiceItemAdjustmentItem.getAmount().compareTo(new BigDecimal("-10")), 0);
        Assert.assertEquals(businessInvoiceItemAdjustmentItem.getItemType(), ..toString());
        Assert.assertEquals(businessInvoiceItemAdjustmentItem.getItemSource(), ..toString());
        // System generated account credit
                                                                                                         ,
                                                                                                         createInvoiceItem(invoiceId.new BigDecimal("10")),
                                                                                                         ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.new BigDecimal("30")),
                                                                                                                                       createInvoiceItem(invoiceId.new BigDecimal("-30")),
                                                                                                                                       createInvoiceItem(invoiceId.new BigDecimal("20"))),
                                                                                                         null,
                                                                                                         null,
                                                                                                         null,
                                                                                                         ,
                                                                                                         ,
                                                                                                         ,
                                                                                                         ,
                                                                                                         );
        Assert.assertEquals(businessCBAItem.getAmount().compareTo(new BigDecimal("10")), 0);
        Assert.assertEquals(businessCBAItem.getItemType(), ..toString());
    }
    @Test(groups = "fast")
    public void testInvoiceAdjustment() throws Exception {
        final UUID invoiceId = UUID.randomUUID();
        Assert.assertFalse(BusinessInvoiceUtils.isInvoiceAdjustmentItem(createInvoiceItem(invoiceId.),
                                                                        ImmutableList.<InvoiceItem>of()));
        Assert.assertTrue(BusinessInvoiceUtils.isInvoiceAdjustmentItem(createInvoiceItem(invoiceId.),
                                                                       ImmutableList.<InvoiceItem>of()));
        final InvoiceItem creditAdj = createInvoiceItem(invoiceId.);
        // Account credit
        Assert.assertFalse(BusinessInvoiceUtils.isInvoiceAdjustmentItem(creditAdj,
                                                                        ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.creditAdj.getAmount().negate()))));
        Assert.assertTrue(BusinessInvoiceUtils.isInvoiceAdjustmentItem(creditAdj,
                                                                       ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.creditAdj.getAmount().negate().add(.)))));
        Assert.assertTrue(BusinessInvoiceUtils.isInvoiceAdjustmentItem(creditAdj,
                                                                       ImmutableList.<InvoiceItem>of(createInvoiceItem(invoiceId.),
                                                                                                     createInvoiceItem(invoiceId.creditAdj.getAmount().negate()))));
    }
New to GrepCode? Check out our FAQ X