Add test for DI constructability of SoneDownloader
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneDownloaderImpl.java
index 3297a0d..d3f23ed 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - SoneDownloader.java - Copyright © 2010–2013 David Roden
+ * Sone - SoneDownloaderImpl.java - Copyright © 2010–2016 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 package net.pterodactylus.sone.core;
 
+import static freenet.support.io.Closer.close;
 import static java.lang.String.format;
 import static java.lang.System.currentTimeMillis;
 import static java.util.concurrent.TimeUnit.DAYS;
+import static java.util.logging.Logger.getLogger;
 
 import java.io.InputStream;
 import java.util.HashSet;
@@ -27,11 +29,11 @@ import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.inject.Inject;
+
 import net.pterodactylus.sone.core.FreenetInterface.Fetched;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.SoneStatus;
-import net.pterodactylus.util.io.Closer;
-import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.service.AbstractService;
 
 import freenet.client.FetchResult;
@@ -41,7 +43,6 @@ import freenet.keys.FreenetURI;
 import freenet.keys.USK;
 import freenet.node.RequestStarter;
 import freenet.support.api.Bucket;
-import com.db4o.ObjectContainer;
 
 import com.google.common.annotations.VisibleForTesting;
 
@@ -53,7 +54,7 @@ import com.google.common.annotations.VisibleForTesting;
 public class SoneDownloaderImpl extends AbstractService implements SoneDownloader {
 
        /** The logger. */
-       private static final Logger logger = Logging.getLogger(SoneDownloaderImpl.class);
+       private static final Logger logger = getLogger(SoneDownloaderImpl.class.getName());
 
        /** The maximum protocol version. */
        private static final int MAX_PROTOCOL_VERSION = 0;
@@ -76,6 +77,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
         * @param freenetInterface
         *              The Freenet interface
         */
+       @Inject
        public SoneDownloaderImpl(Core core, FreenetInterface freenetInterface) {
                this(core, freenetInterface, new SoneParser(core));
        }
@@ -117,7 +119,6 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
                        @Override
                        @SuppressWarnings("synthetic-access")
                        public void onFoundEdition(long edition, USK key,
-                                       ObjectContainer objectContainer,
                                        ClientContext clientContext, boolean metadata,
                                        short codec, byte[] data, boolean newKnownGood,
                                        boolean newSlotToo) {
@@ -237,8 +238,8 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
                } catch (Exception e1) {
                        logger.log(Level.WARNING, String.format("Could not parse Sone from %s!", requestUri), e1);
                } finally {
-                       Closer.close(soneInputStream);
-                       soneBucket.free();
+                       close(soneInputStream);
+                       close(soneBucket);
                }
                return null;
        }