You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LongValueTest.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.ce.task.projectanalysis.formula.counter;
  21. import org.junit.Test;
  22. import static org.assertj.core.api.Assertions.assertThat;
  23. public class LongValueTest {
  24. @Test
  25. public void newly_created_LongVariationValue_is_unset_and_has_value_0() {
  26. verifyUnsetVariationValue(new LongValue());
  27. }
  28. @Test
  29. public void increment_long_sets_LongVariationValue_and_increments_value() {
  30. verifySetVariationValue(new LongValue().increment(10L), 10L);
  31. }
  32. @Test
  33. public void increment_LongVariationValue_has_no_effect_if_arg_is_null() {
  34. verifyUnsetVariationValue(new LongValue().increment(null));
  35. }
  36. @Test
  37. public void increment_LongVariationValue_has_no_effect_if_arg_is_unset() {
  38. verifyUnsetVariationValue(new LongValue().increment(new LongValue()));
  39. }
  40. @Test
  41. public void increment_LongVariationValue_increments_by_the_value_of_the_arg() {
  42. LongValue source = new LongValue().increment(10L);
  43. LongValue target = new LongValue().increment(source);
  44. verifySetVariationValue(target, 10L);
  45. }
  46. @Test
  47. public void multiple_calls_to_increment_LongVariationValue_increments_by_the_value_of_the_arg() {
  48. LongValue target = new LongValue()
  49. .increment(new LongValue().increment(35L))
  50. .increment(new LongValue().increment(10L));
  51. verifySetVariationValue(target, 45L);
  52. }
  53. @Test
  54. public void multiples_calls_to_increment_long_increment_the_value() {
  55. LongValue variationValue = new LongValue()
  56. .increment(10L)
  57. .increment(95L);
  58. verifySetVariationValue(variationValue, 105L);
  59. }
  60. private static void verifyUnsetVariationValue(LongValue variationValue) {
  61. assertThat(variationValue.isSet()).isFalse();
  62. assertThat(variationValue.getValue()).isZero();
  63. }
  64. private static void verifySetVariationValue(LongValue variationValue, long expected) {
  65. assertThat(variationValue.isSet()).isTrue();
  66. assertThat(variationValue.getValue()).isEqualTo(expected);
  67. }
  68. }