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.taskprocessor;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.rules.ExpectedException;
25 import org.sonar.server.computation.queue.CeTaskResult;
27 import static org.assertj.core.api.Assertions.assertThat;
28 import static org.mockito.Mockito.mock;
30 public class MutableTaskResultHolderImplTest {
32 public ExpectedException expectedException = ExpectedException.none();
34 private MutableTaskResultHolder underTest = new MutableTaskResultHolderImpl();
37 public void getResult_throws_ISE_if_no_CeTaskResult_is_set() {
38 expectedException.expect(IllegalStateException.class);
39 expectedException.expectMessage("No CeTaskResult has been set in the holder");
41 underTest.getResult();
45 public void getResult_returns_object_set_with_setResult() {
46 CeTaskResult taskResult = mock(CeTaskResult.class);
48 underTest.setResult(taskResult);
50 assertThat(underTest.getResult()).isSameAs(taskResult);
54 public void setResult_throws_NPE_if_CeTaskResult_argument_is_null() {
55 expectedException.expect(NullPointerException.class);
56 expectedException.expectMessage("taskResult can not be null");
58 underTest.setResult(null);
62 public void setResult_throws_ISE_if_called_twice() {
63 underTest.setResult(mock(CeTaskResult.class));
65 expectedException.expect(IllegalStateException.class);
66 expectedException.expectMessage("CeTaskResult has already been set in the holder");
68 underTest.setResult(mock(CeTaskResult.class));