mirror of
https://github.com/NiciDieNase/chaosflix
synced 2025-03-01 05:37:10 +00:00
Common/Touch: add Tests for all Parcelable-Implementations and fix failing Tests
This commit is contained in:
parent
5236832d23
commit
818db73d44
10 changed files with 285 additions and 111 deletions
common
build.gradle
src
main/java/de/nicidienase/chaosflix/common/mediadata/entities
test/java/de/nicidienase/chaosflix/common
touch
|
@ -60,10 +60,15 @@ android {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
dataBinding {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -92,6 +97,7 @@ dependencies {
|
|||
|
||||
testImplementation "org.mockito:mockito-core:2.11.0"
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.robolectric:robolectric:4.1'
|
||||
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
|
|
|
@ -4,11 +4,11 @@ import android.os.Parcel
|
|||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
open class RelatedEventDto(
|
||||
data class RelatedEventDto(
|
||||
@SerializedName("event_guid") var eventGuid: String,
|
||||
@SerializedName("weight") var weight: Int) : Parcelable {
|
||||
constructor(parcel: Parcel) : this(
|
||||
parcel.readString(),
|
||||
parcel.readString() ?: "",
|
||||
parcel.readInt()) {
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@ import de.nicidienase.chaosflix.common.mediadata.entities.recording.RelatedEvent
|
|||
childColumns = arrayOf("parentEventId"))),
|
||||
indices = [Index("parentEventId","relatedEventGuid",unique = true)]
|
||||
)
|
||||
|
||||
|
||||
class RelatedEvent(
|
||||
data class RelatedEvent(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
var parentEventId: Long,
|
||||
|
@ -29,7 +27,7 @@ class RelatedEvent(
|
|||
constructor(parcel: Parcel) : this(
|
||||
parcel.readLong(),
|
||||
parcel.readLong(),
|
||||
parcel.readString() ?: "",
|
||||
parcel.readString(),
|
||||
parcel.readInt()) {
|
||||
}
|
||||
|
||||
|
|
|
@ -55,10 +55,13 @@ data class Room(var slug: String,
|
|||
return arrayOfNulls(size)
|
||||
}
|
||||
|
||||
fun readMap(input: Parcel): MutableMap<String, StreamEvent> {
|
||||
fun readMap(input: Parcel): MutableMap<String, StreamEvent>? {
|
||||
val keys = input.createStringArray()
|
||||
val urls = input.createTypedArray(StreamEvent.CREATOR)
|
||||
if(keys == null || urls == null){
|
||||
return null
|
||||
}
|
||||
val result = HashMap<String, StreamEvent>()
|
||||
val keys = input.createStringArray() ?: emptyArray()
|
||||
val urls = input.createTypedArray(StreamEvent.CREATOR) ?: emptyArray()
|
||||
for(i in 0 until keys.size - 1){
|
||||
val key = keys[i]
|
||||
val value = urls[i]
|
||||
|
|
|
@ -45,7 +45,40 @@ data class Stream(
|
|||
dest.writeTypedArray(urls,0)
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Stream> {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Stream
|
||||
|
||||
if (slug != other.slug) return false
|
||||
if (display != other.display) return false
|
||||
if (type != other.type) return false
|
||||
if (isTranslated != other.isTranslated) return false
|
||||
if (videoSize != null) {
|
||||
videoSize?.let {
|
||||
if (other.videoSize == null) return false
|
||||
other.videoSize?.let { other ->
|
||||
if (!it.contentEquals(other)) return false
|
||||
}
|
||||
}
|
||||
} else if (other.videoSize != null) return false
|
||||
if (urls != other.urls) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = slug.hashCode()
|
||||
result = 31 * result + display.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
result = 31 * result + isTranslated.hashCode()
|
||||
result = 31 * result + (videoSize?.contentHashCode() ?: 0)
|
||||
result = 31 * result + urls.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
companion object CREATOR : Parcelable.Creator<Stream> {
|
||||
override fun createFromParcel(parcel: Parcel): Stream {
|
||||
return Stream(parcel)
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
package de.nicidienase.chaosflix.common
|
||||
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Conference
|
||||
import de.nicidienase.chaosflix.common.entities.recording.ConferencesWrapper
|
||||
import de.nicidienase.chaosflix.common.entities.recording.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.ConferenceDto
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.ConferencesWrapper
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.EventDto
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
|
||||
class ConferencesWrapperTest{
|
||||
class ConferencesWrapperTest {
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun test1(){
|
||||
val wrapper =
|
||||
ConferencesWrapper(
|
||||
listOf(
|
||||
Conference("42c3", "16:9", "", "42c3,",
|
||||
"42c3","congress/-1c3", "", "",
|
||||
"", "", "foo/42", "",
|
||||
listOf(
|
||||
Event(1, "", "", "", "",
|
||||
"", "", "", arrayOf(""),
|
||||
arrayOf("foo", "bar"), "", "", "",
|
||||
1, "", "", "", "foo/42",
|
||||
"foo/42", emptyList(), emptyList(), false
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
assert(wrapper.conferencesMap.keys.size == 1)
|
||||
}
|
||||
@Test
|
||||
@Ignore
|
||||
fun test1() {
|
||||
val wrapper =
|
||||
ConferencesWrapper(
|
||||
listOf(
|
||||
ConferenceDto("42c3", "16:9", "", "42c3,",
|
||||
"42c3", "congress/-1c3", "", "",
|
||||
"", "", "foo/42", "",
|
||||
listOf(
|
||||
EventDto(1, "", "", "", "",
|
||||
"", "", "", arrayOf(""),
|
||||
arrayOf("foo", "bar"), "", "", "",
|
||||
1, "", "", "", "foo/42",
|
||||
"foo/42", emptyList(), emptyList(), false
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
assert(wrapper.conferencesMap.keys.size == 1)
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package de.nicidienase.chaosflix.common
|
||||
|
||||
|
||||
import com.google.gson.Gson
|
||||
import junit.framework.Assert.assertNotNull
|
||||
import okhttp3.OkHttpClient
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class IntegrationTests {
|
||||
|
||||
lateinit var recordingApi: RecordingService
|
||||
@Before
|
||||
fun init(){
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
val rxJava2CallAdapterFactory = RxJava2CallAdapterFactory.create()
|
||||
val gson = Gson()
|
||||
val gsonConverterFactory = GsonConverterFactory.create(gson)
|
||||
|
||||
val retrofitRecordings = Retrofit.Builder()
|
||||
.baseUrl(recordingUrl)
|
||||
.client(client)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJava2CallAdapterFactory)
|
||||
.build()
|
||||
recordingApi = retrofitRecordings.create(RecordingService::class.java)
|
||||
|
||||
|
||||
// val retrofigStreaming = Retrofit.Builder()
|
||||
// .baseUrl(streamingUrl)
|
||||
// .client(client)
|
||||
// .addConverterFactory(jacksonConverterFactory)
|
||||
// .addCallAdapterFactory(rxJava2CallAdapterFactory)
|
||||
// .build()
|
||||
// streamingApi = retrofigStreaming.create(StreamingService::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test1(){
|
||||
val conferencesWrapper = recordingApi.getConferencesWrapper().blockingGet()
|
||||
val conference = conferencesWrapper.conferences[0]
|
||||
val conferenceWithEvents = recordingApi.getConference(conference.conferenceID).blockingGet()
|
||||
val persistentConference = PersistentConference(conferenceWithEvents)
|
||||
val events = conferenceWithEvents.events?.map { PersistentEvent(it) }
|
||||
assertNotNull(persistentConference)
|
||||
assert(events?.size != 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test2(){
|
||||
val emfCamp = recordingApi.getConference(91).blockingGet()
|
||||
assert("16:9".equals(emfCamp.aspectRatio))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConferencesWrapper(){
|
||||
val conferencesWrapper = recordingApi.getConferencesWrapper().blockingGet()
|
||||
assert(conferencesWrapper.conferencesMap.size.equals(22))
|
||||
}
|
||||
|
||||
companion object {
|
||||
val recordingUrl = "https://api.media.ccc.de"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
package de.nicidienase.chaosflix.common
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.RelatedEventDto
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Conference
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.ConferenceGroup
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.RelatedEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.Room
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.Stream
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamEvent
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamUrl
|
||||
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ParcelableTest {
|
||||
|
||||
@Test
|
||||
fun conferenceParcelableTest() {
|
||||
val conference = Conference(23,
|
||||
42,
|
||||
"GPN42",
|
||||
"16:9",
|
||||
"Gulaschprogramiernach 42",
|
||||
"GPN42",
|
||||
"http://example/com",
|
||||
"http://example/com",
|
||||
"http://example/com",
|
||||
"http://example/com",
|
||||
"http://example/com",
|
||||
"http://example/com",
|
||||
"2042-04-05 23:42:50",
|
||||
false,
|
||||
"2042-04-05 23:42:50")
|
||||
|
||||
assertTrue(conference.equals(Conference.createFromParcel(writeToParcel(conference))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun eventParcelableTest(){
|
||||
val event = Event(23,
|
||||
42,
|
||||
"GPN42",
|
||||
"2314324-12323432-4326546",
|
||||
"Developing for Android 23",
|
||||
"finally in Swift ;)",
|
||||
"And23",
|
||||
"https://example.com/",
|
||||
"Lorem Ipsum",
|
||||
"klingon",
|
||||
"2042.4.5 23:42:59",
|
||||
"2042.4.5 23:42:59",
|
||||
"2042.4.5 23:42:59",
|
||||
1337,
|
||||
"https://example.com/thumb.png",
|
||||
"https://example.com/poster.png",
|
||||
"https://example.com/talk.json",
|
||||
"https://example.com/talk.html",
|
||||
"https://example.com/GPN42",
|
||||
true,
|
||||
230,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
assertTrue(event.equals(Event.createFromParcel(writeToParcel(event))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reletedEventDtoParcelableTest(){
|
||||
val relatedEventDto = RelatedEventDto("ß9834573240ß958", 42)
|
||||
assertTrue(relatedEventDto.equals(RelatedEventDto.createFromParcel(writeToParcel(relatedEventDto))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun conferenceGroupParcelableTest(){
|
||||
val conferenceGroup = ConferenceGroup("conferenceGroup")
|
||||
assertTrue(conferenceGroup.equals(ConferenceGroup.createFromParcel(writeToParcel(conferenceGroup))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun recordingParcelableTest(){
|
||||
val recording = Recording(23,
|
||||
42,
|
||||
2342,
|
||||
1337,
|
||||
"video/mp5",
|
||||
"klingon",
|
||||
"foo.bar",
|
||||
"bar",
|
||||
"foo",
|
||||
true,
|
||||
640,
|
||||
480,
|
||||
"1970.1.1 00:00:00",
|
||||
"https://example.com/recording",
|
||||
"https://example.com/item",
|
||||
"https://example.com/event",
|
||||
"https://example.com/conference",
|
||||
99)
|
||||
assertTrue(recording.equals(Recording.createFromParcel(writeToParcel(recording))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun relatedEventParcelableTest(){
|
||||
val relatedEvent = RelatedEvent(23, 42, "asdlkfjasdf", 99)
|
||||
val other = RelatedEvent.createFromParcel(writeToParcel(relatedEvent))
|
||||
assertTrue(relatedEvent.equals(other))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun roomParcelableTest(){
|
||||
val room = Room("foo",
|
||||
"schedulename",
|
||||
"thumb",
|
||||
"link",
|
||||
"display",
|
||||
null,
|
||||
emptyList())
|
||||
val other = Room.createFromParcel(writeToParcel(room))
|
||||
assertTrue(room.equals(other))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamParcelableTest(){
|
||||
val stream = Stream("slug",
|
||||
"display",
|
||||
"type",
|
||||
true,
|
||||
intArrayOf(640, 480),
|
||||
HashMap<String, StreamUrl>())
|
||||
val other = Stream.createFromParcel(writeToParcel(stream))
|
||||
assertTrue(stream.equals(other))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamEventParcelableTest(){
|
||||
val streamEvent = StreamEvent("title",
|
||||
"speaker",
|
||||
"fstart",
|
||||
"fend",
|
||||
1,
|
||||
23,
|
||||
42,
|
||||
true)
|
||||
assertTrue(streamEvent.equals(StreamEvent.createFromParcel(writeToParcel(streamEvent))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun streamUrlParcelableTest(){
|
||||
val streamUrl = StreamUrl("display", "tech", "url")
|
||||
assertTrue(streamUrl.equals(StreamUrl.createFromParcel(writeToParcel(streamUrl))))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun offlineEventParcelableTest(){
|
||||
val offlineEvent = OfflineEvent(12, "asdflkjasdf",
|
||||
34, 56, "/path/to/file.mp4")
|
||||
assertTrue(offlineEvent.equals(OfflineEvent.createFromParcel(writeToParcel(offlineEvent))))
|
||||
}
|
||||
|
||||
private fun writeToParcel(parcelable: Parcelable): Parcel {
|
||||
val parcel = Parcel.obtain()
|
||||
parcelable.writeToParcel(parcel, 0)
|
||||
parcel.setDataPosition(0)
|
||||
return parcel
|
||||
}
|
||||
}
|
|
@ -91,6 +91,11 @@ android {
|
|||
dataBinding {
|
||||
enabled = true
|
||||
}
|
||||
testOptions {
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
|
@ -123,7 +128,9 @@ dependencies {
|
|||
implementation 'net.rdrei.android.dirchooser:library:3.2@aar'
|
||||
// implementation 'com.gu:option:1.3'
|
||||
implementation 'com.github.guardian:Option:-SNAPSHOT'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.mockito:mockito-core:2.11.0'
|
||||
testImplementation 'org.robolectric:robolectric:4.1'
|
||||
androidTestImplementation('com.android.support.test:rules:0.5') {
|
||||
exclude module: 'support-annotations'
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package de.nicidienase.chaosflix.touch
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import de.nicidienase.chaosflix.touch.playback.PlaybackItem
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class ParcelableTest {
|
||||
|
||||
@Test
|
||||
fun PlaybackItemParcelableTest() {
|
||||
val playbackItem = PlaybackItem("title", "subtitle", "asdlökfjasd", "http://foo.bar/test")
|
||||
assertTrue(playbackItem.equals(PlaybackItem.createFromParcel(writeToParcel(playbackItem))))
|
||||
}
|
||||
|
||||
private fun writeToParcel(parcelable: Parcelable): Parcel {
|
||||
val parcel = Parcel.obtain()
|
||||
parcelable.writeToParcel(parcel, 0)
|
||||
parcel.setDataPosition(0)
|
||||
return parcel
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue