Java Code Examples for java.math.BigDecimal#TEN
The following examples show how to use
java.math.BigDecimal#TEN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InvestmentDescriptorTest.java From robozonky with Apache License 2.0 | 6 votes |
@Test void recommend() { final BigDecimal remainingPrincipal = BigDecimal.TEN; final Investment i = mockInvestment(remainingPrincipal); final InvestmentDescriptor id = new InvestmentDescriptor(i, () -> LOAN, () -> mock(SellInfoImpl.class)); assertThat(id.item()).isSameAs(i); assertThat(id.sellInfo()).isNotEmpty(); final Optional<RecommendedInvestment> r = id.recommend(); assertThat(r).isPresent(); assertSoftly(softly -> { softly.assertThat(r.get() .amount()) .isEqualTo(Money.from(remainingPrincipal)); softly.assertThat(r.get() .descriptor()) .isEqualTo(id); softly.assertThat(r.get() .descriptor() .related()) .isSameAs(LOAN); }); }
Example 2
Source File: MathOperationCalculatorTest.java From jtwig-core with Apache License 2.0 | 6 votes |
@Test public void calculate() throws Exception { BigDecimal expected = BigDecimal.TEN; RenderRequest request = mock(RenderRequest.class, RETURNS_DEEP_STUBS); Position position = mock(Position.class); Object left = new Object(); Object right = new Object(); BigDecimal leftNumber = BigDecimal.ONE; BigDecimal rightNumber = BigDecimal.ZERO; when(request.getEnvironment().getValueEnvironment().getNumberConverter().convert(left)).thenReturn(Converter.Result.defined(leftNumber)); when(request.getEnvironment().getValueEnvironment().getNumberConverter().convert(right)).thenReturn(Converter.Result.defined(rightNumber)); when(simpleBinaryMathCalculator.calculate(request, leftNumber, rightNumber)).thenReturn(expected); Object result = underTest.calculate(request, position, left, right); assertEquals(expected, result); }
Example 3
Source File: StoreServiceImpl.java From spring-boot-jta-atomikos-sample with Apache License 2.0 | 6 votes |
@Transactional() public void transfer() { CapitalAccount ca1 = capitalAccountRepository.findOne(1l); CapitalAccount ca2 = capitalAccountRepository.findOne(2l); RedPacketAccount rp1 = redPacketAccountRepository.findOne(1l); RedPacketAccount rp2 = redPacketAccountRepository.findOne(2l); BigDecimal capital = BigDecimal.TEN; BigDecimal red = BigDecimal.TEN; ca1.transferFrom(capital); ca2.transferTo(capital); capitalAccountRepository.save(ca1); capitalAccountRepository.save(ca2); // if (rp2.getBalanceAmount().compareTo(BigDecimal.ZERO) <= 0) { // throw new RuntimeException("账号异常"); // } rp2.transferFrom(red); rp1.transferTo(red); redPacketAccountRepository.save(rp1); redPacketAccountRepository.save(rp2); }
Example 4
Source File: BigDecSerializer.java From flink with Apache License 2.0 | 6 votes |
public static BigDecimal readBigDecimal(DataInputView source) throws IOException { final BigInteger unscaledValue = BigIntSerializer.readBigInteger(source); if (unscaledValue == null) { return null; } final int scale = source.readInt(); // fast-path for 0, 1, 10 if (scale == 0) { if (unscaledValue == BigInteger.ZERO) { return BigDecimal.ZERO; } else if (unscaledValue == BigInteger.ONE) { return BigDecimal.ONE; } else if (unscaledValue == BigInteger.TEN) { return BigDecimal.TEN; } } // default return new BigDecimal(unscaledValue, scale); }
Example 5
Source File: BigDecComparatorTest.java From flink with Apache License 2.0 | 6 votes |
@Override protected BigDecimal[] getSortedTestData() { return new BigDecimal[] { new BigDecimal("-12.5E1000"), new BigDecimal("-12.5E100"), BigDecimal.valueOf(-12E100), BigDecimal.valueOf(-10000), BigDecimal.valueOf(-1.1), BigDecimal.valueOf(-1), BigDecimal.valueOf(-0.44), BigDecimal.ZERO, new BigDecimal("0.000000000000000000000000001"), new BigDecimal("0.0000001"), new BigDecimal("0.1234123413478523984729447"), BigDecimal.valueOf(1), BigDecimal.valueOf(1.1), BigDecimal.TEN, new BigDecimal("10000"), BigDecimal.valueOf(12E100), new BigDecimal("12.5E100"), new BigDecimal("10E100000"), new BigDecimal("10E1000000000") }; }
Example 6
Source File: BigDecSerializerTest.java From flink with Apache License 2.0 | 5 votes |
@Override protected BigDecimal[] getTestData() { Random rnd = new Random(874597969123412341L); return new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, new BigDecimal(rnd.nextDouble()), new BigDecimal("874597969.1234123413478523984729447"), BigDecimal.valueOf(-1.444), BigDecimal.valueOf(-10000.888)}; }
Example 7
Source File: ValidatorTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Test public void testValidationExpirationNull() { EventModification.AdditionalService invalid = new EventModification.AdditionalService(0, BigDecimal.ONE, true, 1, 100, 1, VALID_INCEPTION, null, BigDecimal.TEN, AdditionalService.VatType.INHERITED, Collections.emptyList(), singletonList(title), singletonList(description), AdditionalService.AdditionalServiceType.DONATION, null); assertFalse(Validator.validateAdditionalService(invalid, errors).isSuccess()); assertTrue(errors.hasFieldErrors()); assertNotNull(errors.getFieldError("additionalServices")); }
Example 8
Source File: BindParameterTypesTest.java From pgadba with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void bindNumerical() throws ExecutionException, InterruptedException, TimeoutException { BigDecimal d = BigDecimal.TEN; try (Session session = ds.getSession()) { CompletionStage<BigDecimal> idF = session.<BigDecimal>rowOperation("select $1::numeric as t") .set("$1", d, PgAdbaType.NUMERIC) .collect(singleCollector(BigDecimal.class)) .submit() .getCompletionStage(); assertEquals(d, get10(idF)); } }
Example 9
Source File: ValidatorTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Test public void testValidationInceptionExpirationNull() { EventModification.AdditionalService invalid = new EventModification.AdditionalService(0, BigDecimal.ONE, true, 1, 100, 1, null, null, BigDecimal.TEN, AdditionalService.VatType.INHERITED, Collections.emptyList(), singletonList(title), singletonList(description), AdditionalService.AdditionalServiceType.DONATION, null); assertFalse(Validator.validateAdditionalService(invalid, errors).isSuccess()); assertTrue(errors.hasFieldErrors()); assertNotNull(errors.getFieldError("additionalServices")); }
Example 10
Source File: ValidatorTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Test public void testValidationSuccess() { EventModification.AdditionalService valid1 = new EventModification.AdditionalService(0, BigDecimal.ZERO, false, 0, -1, 1, VALID_INCEPTION, VALID_EXPIRATION, null, AdditionalService.VatType.NONE, Collections.emptyList(), singletonList(title), singletonList(description), AdditionalService.AdditionalServiceType.DONATION, null); EventModification.AdditionalService valid2 = new EventModification.AdditionalService(0, BigDecimal.ONE, true, 1, 100, 1, VALID_INCEPTION, VALID_EXPIRATION, BigDecimal.TEN, AdditionalService.VatType.INHERITED, Collections.emptyList(), singletonList(title), singletonList(description), AdditionalService.AdditionalServiceType.DONATION, null); assertTrue(Stream.of(valid1, valid2).map(as -> Validator.validateAdditionalService(as, errors)).allMatch(ValidationResult::isSuccess)); assertFalse(errors.hasFieldErrors()); }
Example 11
Source File: ConfigurationManagerIntegrationTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Before public void prepareEnv() { //setup... organizationRepository.create("org", "org", "[email protected]"); Organization organization = organizationRepository.findByName("org").get(); userManager.insertUser(organization.getId(), USERNAME, "test", "test", "[email protected]", Role.OWNER, User.Type.INTERNAL); Map<String, String> desc = new HashMap<>(); desc.put("en", "muh description"); desc.put("it", "muh description"); desc.put("de", "muh description"); List<TicketCategoryModification> ticketsCategory = Collections.singletonList( new TicketCategoryModification(null, "default", 20, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), Collections.singletonMap("en", "desc"), BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty())); EventModification em = new EventModification(null, Event.EventFormat.IN_PERSON, "url", "url", "url", null, null, null, "eventShortName", "displayName", organization.getId(), "muh location", "0.0", "0.0", ZoneId.systemDefault().getId(), desc, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), BigDecimal.TEN, "CHF", 20, BigDecimal.ONE, true, null, ticketsCategory, false, new LocationDescriptor("","","",""), 7, null, null, AlfioMetadata.empty()); eventManager.createEvent(em, USERNAME); event = eventManager.getSingleEvent("eventShortName", "test"); ticketCategory = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0); }
Example 12
Source File: GridBinaryTestClasses.java From ignite with Apache License 2.0 | 4 votes |
/** * */ public void setDefaultData() { b_ = 11; s_ = 22; i_ = 33; bi_ = new BigInteger("33000000000000"); l_ = 44L; f_ = 55f; d_ = 66d; bd_ = new BigDecimal("33000000000000.123456789"); c_ = 'e'; z_ = true; b = 1; s = 2; i = 3; l = 4; f = 5; d = 6; c = 7; z = true; str = "abc"; uuid = new UUID(1, 1); date = new Date(1000000); ts = new Timestamp(100020003); bArr = new byte[] {1, 2, 3}; sArr = new short[] {1, 2, 3}; iArr = new int[] {1, 2, 3}; lArr = new long[] {1, 2, 3}; fArr = new float[] {1, 2, 3}; dArr = new double[] {1, 2, 3}; cArr = new char[] {1, 2, 3}; zArr = new boolean[] {true, false}; strArr = new String[] {"abc", "ab", "a"}; uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)}; bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN}; dateArr = new Date[] {new Date(1000000), new Date(200000)}; tsArr = new Timestamp[] {new Timestamp(100020003), new Timestamp(200030004)}; anEnum = TestObjectEnum.A; enumArr = new TestObjectEnum[] {TestObjectEnum.B}; entry = new GridMapEntry<>(1, "a"); }
Example 13
Source File: TotalTest.java From objectlabkit with Apache License 2.0 | 4 votes |
@Test public void testSumBigDecimalInt() { final Total sum = new Total(BigDecimal.TEN, 4); assertEquals("scale", 4, sum.getTotal().scale()); BigDecimalAssert.assertSameValue("ctor", BigDecimal.TEN, sum.getTotal()); }
Example 14
Source File: Example.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static void main(String[] args) throws IOException { //Model converters will be loaded based on naming convention. //Previously it would be loaded through ServiceLoader.load, //which is still an option if dsljson.configuration name is specified. //DSL-JSON loads all services registered into META-INF/services //and falls back to naming based convention of package._NAME_DslJsonConfiguration if not found //withRuntime is enabled to support runtime analysis for stuff which is not registered by default //Annotation processor will run by default and generate descriptions for JSON encoding/decoding DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().allowArrayFormat(true).includeServiceLoader()); Model instance = new Model(); instance.string = "Hello World!"; instance.number = 42; instance.integers = Arrays.asList(1, 2, 3); instance.decimals = new HashSet<>(Arrays.asList(BigDecimal.ONE, BigDecimal.ZERO)); instance.uuids = new UUID[]{new UUID(1L, 2L), new UUID(3L, 4L)}; instance.longs = new Vector<>(Arrays.asList(1L, 2L)); instance.nested = Arrays.asList(new Model.Nested(), null); instance.inheritance = new Model.ParentClass(); instance.inheritance.a = 5; instance.inheritance.b = 6; instance.iface = new Model.WithCustomCtor(5, 6); instance.person = new ImmutablePerson("first name", "last name", 35, Arrays.asList("DSL", "JSON")); instance.states = Arrays.asList(Model.State.HI, Model.State.LOW); instance.jsonObject = new Model.JsonObjectReference(43, "abcd"); instance.jsonObjects = Collections.singletonList(new Model.JsonObjectReference(34, "dcba")); instance.time = LocalTime.of(12, 15); instance.times = Arrays.asList(null, LocalTime.of(8, 16)); Model.Concrete concrete = new Model.Concrete(); concrete.x = 11; concrete.y = 23; instance.abs = concrete; instance.absList = Arrays.<Model.Abstract>asList(concrete, null, concrete); instance.decimal2 = BigDecimal.TEN; instance.intList = new ArrayList<>(Arrays.asList(123, 456)); instance.map = new HashMap<>(); instance.map.put("abc", 678); instance.map.put("array", new int[] { 2, 4, 8}); instance.factories = Arrays.asList(null, Model.ViaFactory.create("me", 2), Model.ViaFactory.create("you", 3), null); instance.builder = PersonBuilder.builder().firstName("first").lastName("last").age(42).build(); instance.listUnoptimized = new NestedListUnoptimized(1, 2, 3); instance.listOptimized = new NestedListOptimized(4, 5, 6); ByteArrayOutputStream os = new ByteArrayOutputStream(); //To get a pretty JSON output PrettifyOutputStream wrapper can be used dslJson.serialize(instance, new PrettifyOutputStream(os)); byte[] bytes = os.toByteArray(); System.out.println(os); //deserialization using Stream API Model deser = dslJson.deserialize(Model.class, new ByteArrayInputStream(bytes)); System.out.println(deser.string); }
Example 15
Source File: StockPortfolioItemTest.java From Building-Professional-Android-Applications with MIT License | 4 votes |
@NonNull public StockPortfolioItem preparePortfolioItem() { return new StockPortfolioItem("TEST", BigDecimal.TEN, new Date()); }
Example 16
Source File: ArithmeticTest.java From commons-jexl with Apache License 2.0 | 4 votes |
@Test public void testAtomicBoolean() throws Exception { // in a condition JexlScript e = JEXL.createScript("if (x) 1 else 2;", "x"); JexlContext jc = new MapContext(); AtomicBoolean ab = new AtomicBoolean(false); Object o; o = e.execute(jc, ab); Assert.assertEquals("Result is not 2", new Integer(2), o); ab.set(true); o = e.execute(jc, ab); Assert.assertEquals("Result is not 1", new Integer(1), o); // in a binary logical op e = JEXL.createScript("x && y", "x", "y"); ab.set(true); o = e.execute(jc, ab, Boolean.FALSE); Assert.assertFalse((Boolean) o); ab.set(true); o = e.execute(jc, ab, Boolean.TRUE); Assert.assertTrue((Boolean) o); ab.set(false); o = e.execute(jc, ab, Boolean.FALSE); Assert.assertFalse((Boolean) o); ab.set(false); o = e.execute(jc, ab, Boolean.FALSE); Assert.assertFalse((Boolean) o); // in arithmetic op e = JEXL.createScript("x + y", "x", "y"); ab.set(true); o = e.execute(jc, ab, 10); Assert.assertEquals(11, o); o = e.execute(jc, 10, ab); Assert.assertEquals(11, o); o = e.execute(jc, ab, 10.d); Assert.assertEquals(11.d, (Double) o, EPSILON); o = e.execute(jc, 10.d, ab); Assert.assertEquals(11.d, (Double) o, EPSILON); BigInteger bi10 = BigInteger.TEN; ab.set(false); o = e.execute(jc, ab, bi10); Assert.assertEquals(bi10, o); o = e.execute(jc, bi10, ab); Assert.assertEquals(bi10, o); BigDecimal bd10 = BigDecimal.TEN; ab.set(false); o = e.execute(jc, ab, bd10); Assert.assertEquals(bd10, o); o = e.execute(jc, bd10, ab); Assert.assertEquals(bd10, o); // in a (the) monadic op e = JEXL.createScript("!x", "x"); ab.set(true); o = e.execute(jc, ab); Assert.assertFalse((Boolean) o); ab.set(false); o = e.execute(jc, ab); Assert.assertTrue((Boolean) o); // in a (the) monadic op e = JEXL.createScript("-x", "x"); ab.set(true); o = e.execute(jc, ab); Assert.assertFalse((Boolean) o); ab.set(false); o = e.execute(jc, ab); Assert.assertTrue((Boolean) o); }
Example 17
Source File: AimdCongestionControllerTest.java From quilt with Apache License 2.0 | 4 votes |
@Test public void constructWithNullIncreaseAmount() { expectedException.expect(NullPointerException.class); expectedException.expectMessage("increaseAmount must not be null"); new AimdCongestionController(UnsignedLong.ONE, null, BigDecimal.TEN, CodecContextFactory.oer()); }
Example 18
Source File: LocalPaymentCreatorTest.java From apache-camel-invoices with Apache License 2.0 | 4 votes |
@Test public void testCreatePayment() throws PaymentException { Invoice invoice = new Invoice(null, "some-address", "some-account", BigDecimal.TEN); Payment payment = paymentCreator.createPayment(invoice); assertEquals(payment.getReceiverAccount(), invoice.getAccount()); }
Example 19
Source File: MongoDbOrderRepositoryUnitTest.java From tutorials with MIT License | 4 votes |
private Order createOrder(UUID id) { return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product")); }
Example 20
Source File: WaitingQueueProcessorMultiThreadedIntegrationTest.java From alf.io with GNU General Public License v3.0 | 4 votes |
@Test public void testPreRegistration() throws InterruptedException { IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true"); configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true"); initAdminUser(userRepository, authorityRepository); Event event = null; try { List<TicketCategoryModification> categories = Collections.singletonList( new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty())); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository); event = pair.getKey(); waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ENGLISH); waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ITALIAN); assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2); final int parallelism = 10; List<Callable<Void>> calls = new ArrayList<>(parallelism); ExecutorService executor = Executors.newFixedThreadPool(parallelism); final Event eventF = event; for (int i = 0; i < parallelism; i++) { calls.add(() -> { waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF); return null; }); } executor.invokeAll(calls); executor.shutdown(); while(!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) { } assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size()); TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()); eventManager.insertCategory(event.getId(), tcm, pair.getValue()); //System.err.println("------------------------------------------------"); executor = Executors.newFixedThreadPool(parallelism); calls.clear(); for(int i = 0; i < parallelism; i++) { calls.add(() -> { waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF); return null; }); } executor.invokeAll(calls); executor.shutdown(); while(!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) { } List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId()); assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count()); assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING))); assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES))); } finally { if(event != null) { eventManager.deleteEvent(event.getId(), UserManager.ADMIN_USERNAME); } configurationManager.deleteKey(ConfigurationKeys.ENABLE_PRE_REGISTRATION.name()); configurationManager.deleteKey(ConfigurationKeys.ENABLE_WAITING_QUEUE.name()); removeAdminUser(userRepository, authorityRepository); } }