]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Sun, 15 Jul 2012 20:53:58 +0000 (22:53 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Sun, 15 Jul 2012 20:53:58 +0000 (22:53 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/UriReader.java
sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java

index 1f7b1c54613880cc00f03f38a2b9d5442879af3d..2d5ec5dbbbc41cc5e8f7f4355017e27571522227 100644 (file)
@@ -42,7 +42,7 @@ import java.util.List;
  *
  * @since 2.2
  */
-public class HttpDownloader implements UriReader.SchemeProcessor, BatchComponent, ServerComponent {
+public class HttpDownloader extends UriReader.SchemeProcessor implements BatchComponent, ServerComponent {
 
   public static final int TIMEOUT_MILLISECONDS = 20 * 1000;
 
@@ -92,7 +92,7 @@ public class HttpDownloader implements UriReader.SchemeProcessor, BatchComponent
     return Joiner.on(", ").join(descriptions);
   }
 
-  public String description(URI uri) {
+  String description(URI uri) {
     return String.format("%s (%s)", uri.toString(), getProxySynthesis(uri));
   }
 
@@ -170,19 +170,19 @@ public class HttpDownloader implements UriReader.SchemeProcessor, BatchComponent
     }
   }
 
-  public String[] getSupportedSchemes() {
+  String[] getSupportedSchemes() {
     return new String[]{"http", "https"};
   }
 
-  public byte[] readBytes(URI uri) {
+  byte[] readBytes(URI uri) {
     return download(uri);
   }
 
-  public String readString(URI uri, Charset charset) {
+  String readString(URI uri, Charset charset) {
     return downloadPlainText(uri, charset.name());
   }
 
-  public InputStream openStream(URI uri) {
+  InputStream openStream(URI uri) {
     try {
       HttpURLConnection connection = newHttpConnection(uri);
       return connection.getInputStream();
index 105d984dfd83781e2206fde5c84937e9bdd082bf..4a7978ed8ebb1a3d01b902972b21e76845618797 100644 (file)
@@ -94,29 +94,29 @@ public class UriReader implements BatchComponent, ServerComponent {
     return processor;
   }
 
-  static interface SchemeProcessor extends BatchComponent, ServerComponent {
-    String[] getSupportedSchemes();
+  abstract static class SchemeProcessor implements BatchComponent, ServerComponent {
+    abstract String[] getSupportedSchemes();
 
-    byte[] readBytes(URI uri);
+    abstract byte[] readBytes(URI uri);
 
-    String readString(URI uri, Charset charset);
+    abstract String readString(URI uri, Charset charset);
 
-    InputStream openStream(URI uri);
+    abstract InputStream openStream(URI uri);
 
-    String description(URI uri);
+    abstract String description(URI uri);
   }
 
 
   /**
    * This implementation is not exposed in API and is kept private.
    */
-  private static class FileProcessor implements SchemeProcessor {
+  private static class FileProcessor extends SchemeProcessor {
 
     public String[] getSupportedSchemes() {
       return new String[]{"file"};
     }
 
-    public byte[] readBytes(URI uri) {
+    byte[] readBytes(URI uri) {
       try {
         return Files.toByteArray(new File(uri));
       } catch (IOException e) {
@@ -124,7 +124,7 @@ public class UriReader implements BatchComponent, ServerComponent {
       }
     }
 
-    public String readString(URI uri, Charset charset) {
+    String readString(URI uri, Charset charset) {
       try {
         return Files.toString(new File(uri), charset);
       } catch (IOException e) {
@@ -132,7 +132,7 @@ public class UriReader implements BatchComponent, ServerComponent {
       }
     }
 
-    public InputStream openStream(URI uri) {
+    InputStream openStream(URI uri) {
       try {
         return Files.newInputStreamSupplier(new File(uri)).getInput();
       } catch (IOException e) {
@@ -140,7 +140,7 @@ public class UriReader implements BatchComponent, ServerComponent {
       }
     }
 
-    public String description(URI uri) {
+    String description(URI uri) {
       return new File(uri).getAbsolutePath();
     }
   }
index 339659b709addb70722cdd97e29819aaa176101a..05d49987993b3d47743f7920391d1003ae175ec6 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.plugins;
 import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.Test;
+import org.sonar.api.config.Settings;
 import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.UriReader;
 import org.sonar.updatecenter.common.UpdateCenter;
@@ -42,7 +43,8 @@ public class UpdateCenterClientTest {
   @Before
   public void startServer() throws Exception {
     reader = mock(UriReader.class);
-    client = new UpdateCenterClient(reader, new URI(BASE_URL));
+    Settings settings = new Settings().setProperty(UpdateCenterClient.URL_PROPERTY, BASE_URL);
+    client = new UpdateCenterClient(reader, settings);
   }
 
   @Test
@@ -51,8 +53,14 @@ public class UpdateCenterClientTest {
     UpdateCenter center = client.getCenter();
     verify(reader, times(1)).openStream(new URI(BASE_URL));
     assertThat(center.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3"));
+    assertThat(client.getLastRefreshDate()).isNotNull();
   }
 
+  @Test
+    public void not_available_before_initialization() {
+      assertThat(client.getLastRefreshDate()).isNull();
+    }
+
   @Test
   public void ignore_connection_errors() {
     when(reader.openStream(any(URI.class))).thenThrow(new SonarException());