Browse Source

findbugs plugin: improve a unit test

tags/2.6
simonbrandhof 13 years ago
parent
commit
cc199ff792

+ 10
- 3
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsMavenPluginHandlerTest.java View File

import static org.hamcrest.text.StringEndsWith.endsWith; import static org.hamcrest.text.StringEndsWith.endsWith;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties; import org.sonar.api.CoreProperties;
import org.sonar.api.batch.maven.MavenPlugin; import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.profiles.RulesProfile; import org.sonar.api.profiles.RulesProfile;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class FindbugsMavenPluginHandlerTest { public class FindbugsMavenPluginHandlerTest {
private static final String TARGET_TMP_TESTS = "target/tmp-tests";
@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();
private Project project; private Project project;
private ProjectFileSystem fs; private ProjectFileSystem fs;
private File fakeSonarConfig; private File fakeSonarConfig;
private MavenPlugin plugin; private MavenPlugin plugin;
private FindbugsMavenPluginHandler handler; private FindbugsMavenPluginHandler handler;
private File findbugsTempDir;
@Before @Before
public void setup() { public void setup() {
fakeSonarConfig = mock(File.class); fakeSonarConfig = mock(File.class);
plugin = mock(MavenPlugin.class); plugin = mock(MavenPlugin.class);
handler = createMavenPluginHandler(); handler = createMavenPluginHandler();
findbugsTempDir = tempFolder.newFolder("findbugs");
} }
@Test @Test
} }
private void assertFindbugsIncludeFileIsSaved() { private void assertFindbugsIncludeFileIsSaved() {
File findbugsIncludeFile = new File(TARGET_TMP_TESTS + "/target/sonar/findbugs-include.xml");
File findbugsIncludeFile = new File(findbugsTempDir + "/target/sonar/findbugs-include.xml");
assertThat(findbugsIncludeFile.exists(), is(true)); assertThat(findbugsIncludeFile.exists(), is(true));
} }
private void mockProject(String effort) throws URISyntaxException, IOException { private void mockProject(String effort) throws URISyntaxException, IOException {
when(project.getPom()).thenReturn(new MavenProject()); when(project.getPom()).thenReturn(new MavenProject());
when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(new File(TARGET_TMP_TESTS)));
when(project.getFileSystem()).thenReturn(new SimpleProjectFileSystem(findbugsTempDir));
Configuration conf = mock(Configuration.class); Configuration conf = mock(Configuration.class);
when(project.getConfiguration()).thenReturn(conf); when(project.getConfiguration()).thenReturn(conf);

Loading…
Cancel
Save