Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed forName method #689

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.ably.lib.test.android;

import io.ably.lib.push.ActivationStateMachine.CalledActivate;
import io.ably.lib.push.ActivationStateMachine.CalledDeactivate;
import io.ably.lib.push.ActivationStateMachine.Deregistered;
import io.ably.lib.push.ActivationStateMachine.Event;
import io.ably.lib.push.ActivationStateMachine.GotDeviceRegistration;
import io.ably.lib.push.ActivationStateMachine.GotPushDeviceDetails;
import io.ably.lib.push.ActivationStateMachine.RegistrationSynced;
import io.ably.lib.push.ActivationStateMachine.GettingDeviceRegistrationFailed;
import io.ably.lib.push.ActivationStateMachine.GettingPushDeviceDetailsFailed;
import io.ably.lib.push.ActivationStateMachine.SyncRegistrationFailed;
import io.ably.lib.push.ActivationStateMachine.DeregistrationFailed;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class EventTest {

@Test
public void events_subclasses_correctly_constructed_by_name() throws ClassNotFoundException, InstantiationException {

CalledActivate calledActivateEvent = new CalledActivate();
Event calledActivateReconstructed = Event.constructEventByName(calledActivateEvent.getPersistedName());
assertEquals(calledActivateEvent.getClass(), calledActivateReconstructed.getClass());

CalledDeactivate calledDeactivateEvent = new CalledDeactivate();
Event calledDeactivateReconstructed = Event.constructEventByName(calledDeactivateEvent.getPersistedName());
assertEquals(calledDeactivateEvent.getClass(), calledDeactivateReconstructed.getClass());

GotPushDeviceDetails gotPushDeviceDetailsEvent = new GotPushDeviceDetails();
Event gotPushDeviceDetailsReconstructed = Event.constructEventByName(gotPushDeviceDetailsEvent.getPersistedName());
assertEquals(gotPushDeviceDetailsEvent.getClass(), gotPushDeviceDetailsReconstructed.getClass());

RegistrationSynced registrationSyncedEvent = new RegistrationSynced();
Event registrationSyncedReconstructed = Event.constructEventByName(registrationSyncedEvent.getPersistedName());
assertEquals(registrationSyncedEvent.getClass(), registrationSyncedReconstructed.getClass());

Deregistered DeregisteredEvent = new Deregistered();
Event DeregisteredReconstructed = Event.constructEventByName(DeregisteredEvent.getPersistedName());
assertEquals(DeregisteredEvent.getClass(), DeregisteredReconstructed.getClass());
}

@Test
public void events_with_constructor_parameter_cannot_be_restored() {
GotDeviceRegistration gotDeviceRegistration = new GotDeviceRegistration(null);
try{
Event.constructEventByName(gotDeviceRegistration.getPersistedName());
} catch (Exception e) {
assertEquals(InstantiationException.class, e.getClass());
}

GettingDeviceRegistrationFailed gettingDeviceRegistrationFailed = new GettingDeviceRegistrationFailed(null);
try {
Event.constructEventByName(gettingDeviceRegistrationFailed.getPersistedName());
} catch (Exception e) {
assertEquals(InstantiationException.class, e.getClass());
}

GettingPushDeviceDetailsFailed gettingPushDeviceDetailsFailed = new GettingPushDeviceDetailsFailed(null);
try {
Event.constructEventByName(gettingPushDeviceDetailsFailed.getPersistedName());
} catch (Exception e) {
assertEquals(InstantiationException.class, e.getClass());
}

SyncRegistrationFailed syncRegistrationFailed = new SyncRegistrationFailed(null);
try {
Event.constructEventByName(syncRegistrationFailed.getPersistedName());
} catch (Exception e) {
assertEquals(InstantiationException.class, e.getClass());
}

DeregistrationFailed deregistrationFailed = new DeregistrationFailed(null);
try {
Event.constructEventByName(deregistrationFailed.getPersistedName());
} catch (Exception e) {
assertEquals(InstantiationException.class, e.getClass());
}
}

@Test(expected = ClassNotFoundException.class)
public void unknown_events_cannot_be_constructed_by_name() throws Exception {
Event.constructEventByName("notDefinedName");
}
}
Loading