-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #689 from ably/bug-686-remove-use-of-forClass-meth…
…od-push-activation-state-machine Removed forName method
- Loading branch information
Showing
2 changed files
with
357 additions
and
55 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
android/src/androidTest/java/io/ably/lib/test/android/EventTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.