]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9930 improve naming in DefaultTempFolderTest
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 9 Oct 2017 20:45:59 +0000 (22:45 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 11 Oct 2017 11:34:27 +0000 (13:34 +0200)
sonar-plugin-api/src/test/java/org/sonar/api/utils/internal/DefaultTempFolderTest.java

index 62ec60f1d49c257b97559e1916e329a8d78c765e..0efdef9dd48e8bcb39f3fda0a0ed5f5278c90d3d 100644 (file)
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class DefaultTempFolderTest {
 
   @Rule
-  public ExpectedException throwable = ExpectedException.none();
+  public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
@@ -44,52 +44,56 @@ public class DefaultTempFolderTest {
   @Test
   public void createTempFolderAndFile() throws Exception {
     File rootTempFolder = temp.newFolder();
-    DefaultTempFolder tempFolder = new DefaultTempFolder(rootTempFolder);
-    File dir = tempFolder.newDir();
+    DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
+    File dir = underTest.newDir();
     assertThat(dir).exists().isDirectory();
-    File file = tempFolder.newFile();
+    File file = underTest.newFile();
     assertThat(file).exists().isFile();
 
-    new TempFolderCleaner(tempFolder).stop();
+    new TempFolderCleaner(underTest).stop();
     assertThat(rootTempFolder).doesNotExist();
   }
 
   @Test
   public void createTempFolderWithName() throws Exception {
     File rootTempFolder = temp.newFolder();
-    DefaultTempFolder tempFolder = new DefaultTempFolder(rootTempFolder);
-    File dir = tempFolder.newDir("sample");
+    DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
+    File dir = underTest.newDir("sample");
     assertThat(dir).exists().isDirectory();
     assertThat(new File(rootTempFolder, "sample")).isEqualTo(dir);
 
-    new TempFolderCleaner(tempFolder).stop();
+    new TempFolderCleaner(underTest).stop();
     assertThat(rootTempFolder).doesNotExist();
   }
 
   @Test
-  public void createTempFolderWithInvalidName() throws Exception {
+  public void newDir_throws_ISE_if_name_is_not_valid() throws Exception {
     File rootTempFolder = temp.newFolder();
-    DefaultTempFolder tempFolder = new DefaultTempFolder(rootTempFolder);
+    DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
     String tooLong = "tooooolong";
     for (int i = 0; i < 50; i++) {
       tooLong += "tooooolong";
     }
-    throwable.expect(IllegalStateException.class);
-    throwable.expectMessage("Failed to create temp directory");
-    tempFolder.newDir(tooLong);
+
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Failed to create temp directory");
+
+    underTest.newDir(tooLong);
   }
 
   @Test
-  public void createNewFileWithInvalidName() throws Exception {
+  public void newFile_throws_ISE_if_name_is_not_valid() throws Exception {
     File rootTempFolder = temp.newFolder();
-    DefaultTempFolder tempFolder = new DefaultTempFolder(rootTempFolder);
+    DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
     String tooLong = "tooooolong";
     for (int i = 0; i < 50; i++) {
       tooLong += "tooooolong";
     }
-    throwable.expect(IllegalStateException.class);
-    throwable.expectMessage("Failed to create temp file");
-    tempFolder.newFile(tooLong, ".txt");
+
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Failed to create temp file");
+
+    underTest.newFile(tooLong, ".txt");
   }
 
   @Test