import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO;
import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import net.pterodactylus.sone.core.event.InsertionDelayChangedEvent;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.fcp.event.FullAccessRequiredChanged;
import com.google.common.eventbus.EventBus;
-import org.junit.After;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
private final EventBus eventBus = mock(EventBus.class);
private final Preferences preferences = new Preferences(eventBus);
- @After
- public void tearDown() {
- verifyNoMoreInteractions(eventBus);
- }
-
@Test
public void preferencesRetainInsertionDelay() {
preferences.setInsertionDelay(15);
assertThat(preferences.getInsertionDelay(), is(15));
- verify(eventBus).post(any(InsertionDelayChangedEvent.class));
+ }
+
+ @Test
+ public void preferencesSendsEventOnSettingInsertionDelay() {
+ preferences.setInsertionDelay(15);
+ ArgumentCaptor<Object> eventsCaptor = forClass(Object.class);
+ verify(eventBus, atLeastOnce()).post(eventsCaptor.capture());
+ assertThat(eventsCaptor.getAllValues(), hasItem(new InsertionDelayChangedEvent(15)));
}
@Test(expected = IllegalArgumentException.class)
public void preferencesReturnDefaultValueWhenInsertionDelayIsSetToNull() {
preferences.setInsertionDelay(null);
assertThat(preferences.getInsertionDelay(), is(60));
- verify(eventBus).post(any(InsertionDelayChangedEvent.class));
}
@Test
private void verifyFullAccessRequiredChangedEvent(
FullAccessRequired fullAccessRequired) {
ArgumentCaptor<FullAccessRequiredChanged> fullAccessRequiredCaptor =
- ArgumentCaptor.forClass(FullAccessRequiredChanged.class);
+ forClass(FullAccessRequiredChanged.class);
verify(eventBus).post(fullAccessRequiredCaptor.capture());
assertThat(
fullAccessRequiredCaptor.getValue().getFullAccessRequired(),
assertThat(preferences.getFcpFullAccessRequired(), is(ALWAYS));
}
+ @Test
+ public void settingInsertionDelayToValidValueSendsChangeEvent() {
+ preferences.setInsertionDelay(30);
+ ArgumentCaptor<Object> eventsCaptor = forClass(Object.class);
+ verify(eventBus, atLeastOnce()).post(eventsCaptor.capture());
+ assertThat(eventsCaptor.getAllValues(), hasItem(new PreferenceChangedEvent("InsertionDelay", 30)));
+ }
+
}