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.api.batch.sensor.error.internal;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.verifyNoMoreInteractions;
26 import org.junit.Before;
27 import org.junit.Rule;
28 import org.junit.Test;
29 import org.junit.rules.ExpectedException;
30 import org.sonar.api.batch.fs.InputFile;
31 import org.sonar.api.batch.fs.TextPointer;
32 import org.sonar.api.batch.fs.internal.DefaultInputFile;
33 import org.sonar.api.batch.fs.internal.DefaultTextPointer;
34 import org.sonar.api.batch.sensor.internal.SensorStorage;
35 import static org.assertj.core.api.Assertions.assertThat;
37 public class DefaultAnalysisErrorTest {
38 private InputFile inputFile;
39 private SensorStorage storage;
40 private TextPointer textPointer;
43 public ExpectedException exception = ExpectedException.none();
47 inputFile = new DefaultInputFile("module1", "src/File.java");
48 textPointer = new DefaultTextPointer(5, 2);
49 storage = mock(SensorStorage.class);
53 public void test_analysis_error() {
54 DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
55 analysisError.onFile(inputFile)
59 assertThat(analysisError.location()).isEqualTo(textPointer);
60 assertThat(analysisError.message()).isEqualTo("msg");
61 assertThat(analysisError.inputFile()).isEqualTo(inputFile);
65 public void test_save() {
66 DefaultAnalysisError analysisError = new DefaultAnalysisError(storage);
67 analysisError.onFile(inputFile).save();
69 verify(storage).store(analysisError);
70 verifyNoMoreInteractions(storage);
74 public void test_must_have_file() {
75 exception.expect(NullPointerException.class);
76 new DefaultAnalysisError(storage).save();