Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
linsang21 committed Sep 4, 2024
1 parent 46d1e6b commit 0b77b04
Show file tree
Hide file tree
Showing 74 changed files with 2,880 additions and 141 deletions.
11 changes: 7 additions & 4 deletions amazon-chime-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.dokka.gradle.DokkaTask
apply from: rootProject.file('publishing.gradle')
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'jacoco'

Expand Down Expand Up @@ -39,7 +38,7 @@ android {

kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += ["-Xjvm-default=enable"]
freeCompilerArgs += ["-Xjvm-default=all"]
}

buildTypes {
Expand All @@ -61,6 +60,10 @@ android {
jacoco {
includeNoLocationClasses = true
}
jvmArgs(
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED"
)
}
// This causes system calls to return default (i.e. null or zero) values rather then
// immediately throwing exceptions. Without this, tests covering anything with significant OpenGLES or
Expand Down Expand Up @@ -145,11 +148,11 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3'
testImplementation 'junit:junit:4.12'
testImplementation "io.mockk:mockk:1.10.0"
testImplementation "io.mockk:mockk:1.13.12"
// Android Test only
androidTestImplementation 'androidx.test:core:1.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'io.mockk:mockk-android:1.10.0'
androidTestImplementation 'io.mockk:mockk-android:1.13.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ class DefaultAudioClientObserver(
meetingStatsCollector.incrementPoorConnectionCount()
notifyAudioClientObserver { observer -> observer.onConnectionBecamePoor() }
}
else -> Unit
}
else -> Unit
}
}
SessionStateControllerAction.Reconnecting -> {
Expand All @@ -156,8 +158,10 @@ class DefaultAudioClientObserver(
}
handleOnAudioSessionFailed(newAudioStatus)
}
else -> Unit
}
}
else -> Unit
}
currentAudioState = newAudioState
currentAudioStatus = newAudioStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ConsoleLogger(private var level: LogLevel = LogLevel.INFO) : Logger {
LogLevel.INFO -> Log.i(tag, msg)
LogLevel.WARN -> Log.w(tag, msg)
LogLevel.ERROR -> Log.e(tag, msg)
else -> Unit
}
}
}
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion project.ext.chimeCompileSdkVersion
buildToolsVersion project.ext.chimeBuildToolsVersion
compileSdk project.ext.chimeCompileSdkVersion
buildToolsVersion = project.ext.chimeBuildToolsVersion
defaultConfig {
applicationId "com.amazonaws.services.chime.sdkdemo"
minSdkVersion project.ext.chimeMinSdkVersion
Expand All @@ -29,6 +27,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.amazonaws.services.chime.sdk.meetings.audiovideo.TranscriptItemType
import com.amazonaws.services.chime.sdkdemo.R
import com.amazonaws.services.chime.sdkdemo.data.Caption
import com.amazonaws.services.chime.sdkdemo.databinding.RowCaptionBinding
import com.amazonaws.services.chime.sdkdemo.utils.inflate
import kotlinx.android.synthetic.main.row_caption.view.captionText
import kotlinx.android.synthetic.main.row_caption.view.speakerName

class CaptionAdapter(
private val captions: Collection<Caption>
Expand Down Expand Up @@ -49,15 +48,15 @@ class CaptionHolder(inflatedView: View) :
private const val FILTERED_CAPTION_FIRST_INDEX = "["
}

private var view: View = inflatedView
private val binding = RowCaptionBinding.bind(inflatedView)

fun bindCaption(caption: Caption, position: Int) {
val speakerName = caption.speakerName ?: ""

val captionTextBackgroundColor = caption.speakerName?.let { R.color.colorWhite } ?: R.color.colorMissingSpeaker
view.captionText.setBackgroundResource(captionTextBackgroundColor)
view.speakerName.text = speakerName
view.captionText.text = caption.content
binding.captionText.setBackgroundResource(captionTextBackgroundColor)
binding.speakerName.text = speakerName
binding.captionText.text = caption.content
val spannable = SpannableString(caption.content)
caption.entities?.let { contents ->
// Highlight PII identified and redacted words.
Expand All @@ -69,7 +68,7 @@ class CaptionHolder(inflatedView: View) :
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
} ?: run { view.captionText.setTextColor(Color.BLACK) }
} ?: run { binding.captionText.setTextColor(Color.BLACK) }
caption.items?.let { items ->
// Underline words with low confidence score.
items.forEach { item ->
Expand All @@ -85,8 +84,8 @@ class CaptionHolder(inflatedView: View) :
}
}
}
view.captionText.text = spannable
view.captionText.contentDescription = "caption-$position"
binding.captionText.text = spannable
binding.captionText.contentDescription = "caption-$position"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.amazonaws.services.chime.sdkdemo.R
import com.amazonaws.services.chime.sdkdemo.data.Message
import com.amazonaws.services.chime.sdkdemo.databinding.RowMessageBinding
import com.amazonaws.services.chime.sdkdemo.utils.inflate
import kotlinx.android.synthetic.main.row_message.view.messageText
import kotlinx.android.synthetic.main.row_message.view.messageTimestamp
import kotlinx.android.synthetic.main.row_message.view.senderName

class MessageAdapter(
private val messages: Collection<Message>
Expand All @@ -36,14 +34,14 @@ class MessageAdapter(

class MessageHolder(inflatedView: View) :
RecyclerView.ViewHolder(inflatedView) {
private var view: View = inflatedView
private val binding = RowMessageBinding.bind(inflatedView)

fun bindMessage(message: Message) {
view.senderName.text = message.senderName
view.messageTimestamp.text = message.displayTime
view.messageText.text = message.text
view.messageText.contentDescription = message.text
view.messageText.textAlignment =
binding.senderName.text = message.senderName
binding.messageTimestamp.text = message.displayTime
binding.messageText.text = message.text
binding.messageText.contentDescription = message.text
binding.messageText.textAlignment =
if (message.isLocal) View.TEXT_ALIGNMENT_TEXT_END else View.TEXT_ALIGNMENT_TEXT_START
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.amazonaws.services.chime.sdkdemo.R
import com.amazonaws.services.chime.sdkdemo.data.MetricData
import com.amazonaws.services.chime.sdkdemo.databinding.RowMetricBinding
import com.amazonaws.services.chime.sdkdemo.utils.inflate
import kotlinx.android.synthetic.main.row_metric.view.*

class MetricAdapter(
private val metricsList: Collection<MetricData>
Expand All @@ -34,14 +34,14 @@ class MetricAdapter(
class MetricHolder(inflatedView: View) :
RecyclerView.ViewHolder(inflatedView) {

private var view: View = inflatedView
private val binding = RowMetricBinding.bind(inflatedView)

fun bindMetrics(metric: MetricData) {
val name = metric.metricName
val value = metric.metricValue.toString()
view.metricName.text = name
view.metricValue.text = value
view.metricName.contentDescription = "$name metric"
view.metricValue.contentDescription = "$name value"
binding.metricName.text = name
binding.metricValue.text = value
binding.metricName.contentDescription = "$name metric"
binding.metricValue.contentDescription = "$name value"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import com.amazonaws.services.chime.sdk.meetings.audiovideo.VolumeLevel
import com.amazonaws.services.chime.sdk.meetings.internal.AttendeeStatus
import com.amazonaws.services.chime.sdkdemo.R
import com.amazonaws.services.chime.sdkdemo.data.RosterAttendee
import com.amazonaws.services.chime.sdkdemo.databinding.RowRosterBinding
import com.amazonaws.services.chime.sdkdemo.utils.inflate
import kotlinx.android.synthetic.main.row_roster.view.activeSpeakerIndicator
import kotlinx.android.synthetic.main.row_roster.view.attendeeName
import kotlinx.android.synthetic.main.row_roster.view.attendeeVolume

class RosterAdapter(
private val roster: Collection<RosterAttendee>
) :
Expand All @@ -40,14 +37,14 @@ class RosterAdapter(
class RosterHolder(inflatedView: View) :
RecyclerView.ViewHolder(inflatedView) {

private var view: View = inflatedView
private val binding = RowRosterBinding.bind(inflatedView)

fun bindAttendee(attendee: RosterAttendee) {
val attendeeName = attendee.attendeeName
view.attendeeName.text = attendeeName
view.attendeeName.contentDescription = attendeeName
view.activeSpeakerIndicator.visibility = if (attendee.isActiveSpeaker) View.VISIBLE else View.INVISIBLE
view.activeSpeakerIndicator.contentDescription = if (attendee.isActiveSpeaker) "${attendee.attendeeName} Active" else ""
binding.attendeeName.text = attendeeName
binding.attendeeName.contentDescription = attendeeName
binding.activeSpeakerIndicator.visibility = if (attendee.isActiveSpeaker) View.VISIBLE else View.INVISIBLE
binding.activeSpeakerIndicator.contentDescription = if (attendee.isActiveSpeaker) "${attendee.attendeeName} Active" else ""

if (attendee.attendeeStatus == AttendeeStatus.Joined) {
if (attendee.signalStrength == SignalStrength.None ||
Expand All @@ -58,35 +55,35 @@ class RosterHolder(inflatedView: View) :
} else {
R.drawable.ic_microphone_poor_connectivity
}
view.attendeeVolume.setImageResource(drawable)
view.contentDescription = "$attendeeName Signal Strength Poor"
binding.attendeeVolume.setImageResource(drawable)
binding.attendeeVolume.contentDescription = "$attendeeName Signal Strength Poor"
} else {
when (attendee.volumeLevel) {
VolumeLevel.Muted -> {
view.attendeeVolume.setImageResource(R.drawable.ic_microphone_disabled)
view.attendeeVolume.contentDescription = "$attendeeName Muted"
binding.attendeeVolume.setImageResource(R.drawable.ic_microphone_disabled)
binding.attendeeVolume.contentDescription = "$attendeeName Muted"
}
VolumeLevel.NotSpeaking -> {
view.attendeeVolume.setImageResource(R.drawable.ic_microphone_enabled)
view.attendeeVolume.contentDescription = "$attendeeName Not Speaking"
binding.attendeeVolume.setImageResource(R.drawable.ic_microphone_enabled)
binding.attendeeVolume.contentDescription = "$attendeeName Not Speaking"
}
VolumeLevel.Low -> {
view.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_1)
view.attendeeVolume.contentDescription = "$attendeeName Speaking"
binding.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_1)
binding.attendeeVolume.contentDescription = "$attendeeName Speaking"
}
VolumeLevel.Medium -> {
view.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_2)
view.attendeeVolume.contentDescription = "$attendeeName Speaking"
binding.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_2)
binding.attendeeVolume.contentDescription = "$attendeeName Speaking"
}
VolumeLevel.High -> {
view.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_3)
view.attendeeVolume.contentDescription = "$attendeeName Speaking"
binding.attendeeVolume.setImageResource(R.drawable.ic_microphone_audio_3)
binding.attendeeVolume.contentDescription = "$attendeeName Speaking"
}
}
}
view.attendeeVolume.visibility = View.VISIBLE
binding.attendeeVolume.visibility = View.VISIBLE
} else {
view.attendeeVolume.visibility = View.GONE
binding.attendeeVolume.visibility = View.GONE
}
}
}
Loading

0 comments on commit 0b77b04

Please sign in to comment.