🎨 Replace UpdateFoundEvent with Kotlin version
[Sone.git] / src / test / java / net / pterodactylus / sone / core / ConfigurationSoneParserTest.java
index c8742c2..4edc1b7 100644 (file)
@@ -1,10 +1,10 @@
 package net.pterodactylus.sone.core;
 
 import static com.google.common.base.Optional.of;
-import static net.pterodactylus.sone.Matchers.isAlbum;
-import static net.pterodactylus.sone.Matchers.isImage;
-import static net.pterodactylus.sone.Matchers.isPost;
-import static net.pterodactylus.sone.Matchers.isPostReply;
+import static net.pterodactylus.sone.test.Matchers.isAlbum;
+import static net.pterodactylus.sone.test.Matchers.isImage;
+import static net.pterodactylus.sone.test.Matchers.isPost;
+import static net.pterodactylus.sone.test.Matchers.isPostReply;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -13,8 +13,8 @@ import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -22,12 +22,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicReference;
 
-import net.pterodactylus.sone.TestAlbumBuilder;
-import net.pterodactylus.sone.TestImageBuilder;
-import net.pterodactylus.sone.TestPostBuilder;
-import net.pterodactylus.sone.TestPostReplyBuilder;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidAlbumFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidImageFound;
 import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidParentAlbumFound;
@@ -47,9 +42,12 @@ import net.pterodactylus.sone.database.PostBuilder;
 import net.pterodactylus.sone.database.PostBuilderFactory;
 import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.sone.database.PostReplyBuilderFactory;
+import net.pterodactylus.sone.test.TestAlbumBuilder;
+import net.pterodactylus.sone.test.TestImageBuilder;
+import net.pterodactylus.sone.test.TestPostBuilder;
+import net.pterodactylus.sone.test.TestPostReplyBuilder;
+import net.pterodactylus.sone.test.TestValue;
 import net.pterodactylus.util.config.Configuration;
-import net.pterodactylus.util.config.ConfigurationException;
-import net.pterodactylus.util.config.Value;
 
 import com.google.common.base.Optional;
 import org.hamcrest.Matchers;
@@ -59,8 +57,6 @@ import org.mockito.stubbing.Answer;
 
 /**
  * Unit test for {@link ConfigurationSoneParser}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
  */
 public class ConfigurationSoneParserTest {
 
@@ -90,9 +86,9 @@ public class ConfigurationSoneParserTest {
 
        private void setupEmptyProfile() {
                when(configuration.getStringValue(anyString())).thenReturn(
-                               new TestValue<String>(null));
+                               TestValue.<String>from(null));
                when(configuration.getIntValue(anyString())).thenReturn(
-                               new TestValue<Integer>(null));
+                               TestValue.<Integer>from(null));
        }
 
        @Test
@@ -130,12 +126,12 @@ public class ConfigurationSoneParserTest {
 
        private void setupString(String nodeName, String value) {
                when(configuration.getStringValue(eq(nodeName))).thenReturn(
-                               new TestValue<String>(value));
+                               TestValue.from(value));
        }
 
        private void setupInteger(String nodeName, Integer value) {
                when(configuration.getIntValue(eq(nodeName))).thenReturn(
-                               new TestValue<Integer>(value));
+                               TestValue.from(value));
        }
 
        @Test
@@ -182,7 +178,7 @@ public class ConfigurationSoneParserTest {
 
        private void setupLong(String nodeName, Long value) {
                when(configuration.getLongValue(eq(nodeName))).thenReturn(
-                               new TestValue<Long>(value));
+                               TestValue.from(value));
        }
 
        @Test(expected = InvalidPostFound.class)
@@ -335,15 +331,15 @@ public class ConfigurationSoneParserTest {
                                                albumBuilderFactory);
                assertThat(topLevelAlbums, hasSize(2));
                Album firstAlbum = topLevelAlbums.get(0);
-               assertThat(firstAlbum, isAlbum("A1", null, "T1", "D1", "I1"));
+               assertThat(firstAlbum, isAlbum("A1", null, "T1", "D1"));
                assertThat(firstAlbum.getAlbums(), emptyIterable());
                assertThat(firstAlbum.getImages(), emptyIterable());
                Album secondAlbum = topLevelAlbums.get(1);
-               assertThat(secondAlbum, isAlbum("A2", null, "T2", "D2", null));
+               assertThat(secondAlbum, isAlbum("A2", null, "T2", "D2"));
                assertThat(secondAlbum.getAlbums(), hasSize(1));
                assertThat(secondAlbum.getImages(), emptyIterable());
                Album thirdAlbum = secondAlbum.getAlbums().get(0);
-               assertThat(thirdAlbum, isAlbum("A3", "A2", "T3", "D3", "I3"));
+               assertThat(thirdAlbum, isAlbum("A3", "A2", "T3", "D3"));
                assertThat(thirdAlbum.getAlbums(), emptyIterable());
                assertThat(thirdAlbum.getImages(), emptyIterable());
        }
@@ -523,30 +519,4 @@ public class ConfigurationSoneParserTest {
                configurationSoneParser.parseImages(createImageBuilderFactory());
        }
 
-       private static class TestValue<T> implements Value<T> {
-
-               private final AtomicReference<T> value = new AtomicReference<T>();
-
-               public TestValue(T originalValue) {
-                       value.set(originalValue);
-               }
-
-               @Override
-               public T getValue() throws ConfigurationException {
-                       return value.get();
-               }
-
-               @Override
-               public T getValue(T defaultValue) {
-                       final T realValue = value.get();
-                       return (realValue != null) ? realValue : defaultValue;
-               }
-
-               @Override
-               public void setValue(T newValue) throws ConfigurationException {
-                       value.set(newValue);
-               }
-
-       }
-
 }