@Test public void testGetNextOrderNumber() throws Exception { final GenericDAO<CustomerOrder, Long> customerOrderDao = this.mockery.mock(GenericDAO.class, "customerOrderDao"); final LocalDateTime[] now = new LocalDateTime[] { DateUtils.ldtParseSDT("2017-12-25 11:11:11") }; final LocalDateTime dec01 = DateUtils.ldtParseSDT("2017-12-01 00:00:00"); final LocalDateTime jan01 = DateUtils.ldtParseSDT("2018-01-01 00:00:00"); final LocalDateTime feb01 = DateUtils.ldtParseSDT("2018-02-01 00:00:00"); DefaultOrderNumberGeneratorImpl defaultOrderNumberGenerator = new DefaultOrderNumberGeneratorImpl(customerOrderDao) { @Override LocalDateTime now() { return now[0]; } }; this.mockery.checking(new Expectations() {{ oneOf(customerOrderDao).findCountByCriteria( " where e.orderTimestamp >= ?1 and e.orderStatus <> ?2", dec01, CustomerOrder.ORDER_STATUS_NONE ); will(returnValue(0)); oneOf(customerOrderDao).findCountByCriteria( " where e.orderTimestamp >= ?1 and e.orderStatus <> ?2", jan01, CustomerOrder.ORDER_STATUS_NONE ); will(returnValue(0)); oneOf(customerOrderDao).findCountByCriteria( " where e.orderTimestamp >= ?1 and e.orderStatus <> ?2", feb01, CustomerOrder.ORDER_STATUS_NONE ); will(returnValue(0)); }}); int prevMonth = 11; int prev = 0; int countMth = 0; for (int day = 1; day < 40; day++) { final int month = now[0].getMonthValue(); if (month != prevMonth) { prevMonth = month; prev = 0; countMth++; } for (int i = 1; i <= 10000; i = i + 1) { String orderNum = defaultOrderNumberGenerator.getNextOrderNumber(); String expected = "-" + (i + prev); assertEquals(expected, orderNum.substring(orderNum.indexOf("-"))); } now[0] = now[0].plusDays(1); prev += 10000; } assertEquals(3, countMth); this.mockery.assertIsSatisfied(); }
@Override public synchronized String getNextOrderNumber() { final LocalDateTime now = now(); final String datePart = datePart(now); final String sequencePart = getOrderSequence(now); return datePart + '-' + sequencePart; }
DefaultOrderNumberGeneratorImpl implements OrderNumberGenerator { @Override public synchronized String getNextOrderNumber() { final LocalDateTime now = now(); final String datePart = datePart(now); final String sequencePart = getOrderSequence(now); return datePart + '-' + sequencePart; } }
DefaultOrderNumberGeneratorImpl implements OrderNumberGenerator { @Override public synchronized String getNextOrderNumber() { final LocalDateTime now = now(); final String datePart = datePart(now); final String sequencePart = getOrderSequence(now); return datePart + '-' + sequencePart; } DefaultOrderNumberGeneratorImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao);   DefaultOrderNumberGeneratorImpl(); }
DefaultOrderNumberGeneratorImpl implements OrderNumberGenerator { @Override public synchronized String getNextOrderNumber() { final LocalDateTime now = now(); final String datePart = datePart(now); final String sequencePart = getOrderSequence(now); return datePart + '-' + sequencePart; } DefaultOrderNumberGeneratorImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao);   DefaultOrderNumberGeneratorImpl(); @Override synchronized String getNextOrderNumber(); }
DefaultOrderNumberGeneratorImpl implements OrderNumberGenerator { @Override public synchronized String getNextOrderNumber() { final LocalDateTime now = now(); final String datePart = datePart(now); final String sequencePart = getOrderSequence(now); return datePart + '-' + sequencePart; } DefaultOrderNumberGeneratorImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao);   DefaultOrderNumberGeneratorImpl(); @Override synchronized String getNextOrderNumber();  }