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
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
private void setupLong(String nodeName, Long value) {
when(configuration.getLongValue(eq(nodeName))).thenReturn(
- new TestValue<Long>(value));
+ TestValue.from(value));
}
@Test(expected = InvalidPostFound.class)
setupIntValue("PositiveTrust", 50);
setupIntValue("NegativeTrust", -50);
when(configuration.getStringValue("Option/TrustComment")).thenReturn(
- new TestValue<String>("Trusted"));
+ TestValue.from("Trusted"));
setupBooleanValue("ActivateFcpInterface", true);
setupIntValue("FcpFullAccessRequired", 1);
}
private void setupIntValue(String optionName, int value) {
when(configuration.getIntValue("Option/" + optionName)).thenReturn(
- new TestValue<Integer>(value));
+ TestValue.from(value));
}
private void setupBooleanValue(String optionName, boolean value) {
when(configuration.getBooleanValue(
"Option/" + optionName)).thenReturn(
- new TestValue<Boolean>(value));
+ TestValue.from(value));
}
@Test
import net.pterodactylus.sone.TestValue;
import net.pterodactylus.util.config.Configuration;
import net.pterodactylus.util.config.ConfigurationException;
+import net.pterodactylus.util.config.Value;
import org.junit.Test;
@Test
public void loaderCanLoadKnownPosts() {
when(configuration.getStringValue("KnownPosts/0/ID"))
- .thenReturn(new TestValue<String>("Post2"));
+ .thenReturn(TestValue.from("Post2"));
when(configuration.getStringValue("KnownPosts/1/ID"))
- .thenReturn(new TestValue<String>("Post1"));
+ .thenReturn(TestValue.from("Post1"));
when(configuration.getStringValue("KnownPosts/2/ID"))
- .thenReturn(new TestValue<String>(null));
+ .thenReturn(TestValue.<String>from(null));
Set<String> knownPosts = configurationLoader.loadKnownPosts();
assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
}
@Test
public void loaderCanLoadKnownPostReplies() {
when(configuration.getStringValue("KnownReplies/0/ID"))
- .thenReturn(new TestValue<String>("PostReply2"));
+ .thenReturn(TestValue.from("PostReply2"));
when(configuration.getStringValue("KnownReplies/1/ID"))
- .thenReturn(new TestValue<String>("PostReply1"));
+ .thenReturn(TestValue.from("PostReply1"));
when(configuration.getStringValue("KnownReplies/2/ID"))
- .thenReturn(new TestValue<String>(null));
+ .thenReturn(TestValue.<String>from(null));
Set<String> knownPosts = configurationLoader.loadKnownPostReplies();
assertThat(knownPosts,
containsInAnyOrder("PostReply1", "PostReply2"));
@Test
public void loaderCanLoadBookmarkedPosts() {
when(configuration.getStringValue("Bookmarks/Post/0/ID"))
- .thenReturn(new TestValue<String>("Post2"));
+ .thenReturn(TestValue.from("Post2"));
when(configuration.getStringValue("Bookmarks/Post/1/ID"))
- .thenReturn(new TestValue<String>("Post1"));
+ .thenReturn(TestValue.from("Post1"));
when(configuration.getStringValue("Bookmarks/Post/2/ID"))
- .thenReturn(new TestValue<String>(null));
+ .thenReturn(TestValue.<String>from(null));
Set<String> knownPosts = configurationLoader.loadBookmarkedPosts();
assertThat(knownPosts, containsInAnyOrder("Post1", "Post2"));
}
@Test
public void loaderCanSaveBookmarkedPosts() throws ConfigurationException {
- final TestValue<String> post1 = new TestValue<String>(null);
- final TestValue<String> post2 = new TestValue<String>(null);
- final TestValue<String> post3 = new TestValue<String>(null);
- when(configuration.getStringValue("Bookmarks/Post/0/ID"))
- .thenReturn(post1);
- when(configuration.getStringValue("Bookmarks/Post/1/ID"))
- .thenReturn(post2);
- when(configuration.getStringValue("Bookmarks/Post/2/ID"))
- .thenReturn(post3);
- HashSet<String> originalPosts =
- new HashSet<String>(asList("Post1", "Post2"));
+ final Value<String> post1 = TestValue.<String>from(null);
+ final Value<String> post2 = TestValue.<String>from(null);
+ final Value<String> post3 = TestValue.<String>from(null);
+ when(configuration.getStringValue("Bookmarks/Post/0/ID")).thenReturn(post1);
+ when(configuration.getStringValue("Bookmarks/Post/1/ID")).thenReturn(post2);
+ when(configuration.getStringValue("Bookmarks/Post/2/ID")).thenReturn(post3);
+ HashSet<String> originalPosts = new HashSet<String>(asList("Post1", "Post2"));
configurationLoader.saveBookmarkedPosts(originalPosts);
- HashSet<String> extractedPosts = new HashSet<String>(
- asList(post1.getValue(), post2.getValue()));
+ HashSet<String> extractedPosts =
+ new HashSet<String>(asList(post1.getValue(), post2.getValue()));
assertThat(extractedPosts, containsInAnyOrder("Post1", "Post2"));
assertThat(post3.getValue(), nullValue());
}
private void initializeFriends() {
when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/0/ID")).thenReturn(
- new TestValue<String>("Friend1"));
+ TestValue.from("Friend1"));
when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/1/ID")).thenReturn(
- new TestValue<String>("Friend2"));
+ TestValue.from("Friend2"));
when(configuration.getStringValue("Sone/" + SONE_ID + "/Friends/2/ID")).thenReturn(
- new TestValue<String>(null));
+ TestValue.<String>from(null));
}
@Test
when(configuration.getStringValue(anyString())).thenAnswer(new Answer<Value<String>>() {
@Override
public Value<String> answer(InvocationOnMock invocation) throws Throwable {
- Value<String> stringValue = new TestValue(null);
+ Value<String> stringValue = TestValue.from(null);
configurationValues.put((String) invocation.getArguments()[0], stringValue);
return stringValue;
}