3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.computation.task.projectanalysis.period;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
26 import static org.assertj.core.api.Assertions.assertThat;
28 public class PeriodsHolderImplTest {
31 public ExpectedException thrown = ExpectedException.none();
33 private PeriodsHolderImpl underTest = new PeriodsHolderImpl();
36 public void get_period() {
37 Period period = createPeriod();
38 underTest.setPeriod(period);
40 assertThat(underTest.getPeriod()).isEqualTo(period);
44 public void get_period_throws_illegal_state_exception_if_not_initialized() {
45 thrown.expect(IllegalStateException.class);
46 thrown.expectMessage("Period have not been initialized yet");
48 new PeriodsHolderImpl().getPeriod();
52 public void setPeriod_throws_ISE_if_already_initialized() {
53 thrown.expect(IllegalStateException.class);
54 thrown.expectMessage("Period have already been initialized");
56 underTest.setPeriod(createPeriod());
57 underTest.setPeriod(createPeriod());
61 public void hasPeriod_returns_false_if_holder_is_empty() {
62 underTest.setPeriod(null);
63 assertThat(underTest.hasPeriod()).isFalse();
67 public void hasPeriod_returns_true_only_if_period_exists_in_holder() {
68 underTest.setPeriod(createPeriod());
69 assertThat(underTest.hasPeriod()).isTrue();
73 public void hasPeriod_throws_ISE_if_not_initialized() {
74 thrown.expect(IllegalStateException.class);
75 thrown.expectMessage("Period have not been initialized yet");
77 underTest.hasPeriod();
80 private static Period createPeriod() {
81 return new Period(1, 1 + "mode", null, 1000L, "U1");