I am currently using Glide to upload images to my app. It works fine until I have to load an image into a CustomInfoWindow. I get a warning that has to do with the problem, also I think it has something to do with the available cache.
Warning:
Logcat:
W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a #GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
I/DynamiteModule: Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:5
I/DynamiteModule: Selected remote version of com.google.android.gms.googlecertificates, version >= 5
W/zygote: Skipping duplicate class check due to unrecognized classloader
I/zygote: Do full code cache collection, code=508KB, data=376KB
I/zygote: After code cache collection, code=402KB, data=275KB
build.gradle,import and class:
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
applicationId "com.example.xxxx"
minSdkVersion 21
targetSdkVersion 30
versionCode 2
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-rc1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.4.4'
implementation 'com.google.firebase:firebase-auth-ktx:19.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'com.android.support:appcompat-v7'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
implementation 'com.google.firebase:firebase-firestore:21.5.0'
implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'com.google.firebase:firebase-core:17.4.4'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
implementation 'com.google.firebase:firebase-database-ktx:19.3.1'
implementation 'com.google.firebase:firebase-messaging:20.2.3'
implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
}
import
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Point
import android.location.Location
import android.location.LocationManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.bumptech.glide.Glide
import com.example.mappet001.reports.ReportPet
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.*
import com.google.firebase.Timestamp
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FieldValue
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.GeoPoint
import com.google.firebase.storage.FirebaseStorage
import kotlinx.android.synthetic.main.activity_maps.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.form_report.*
import kotlinx.android.synthetic.main.reportvisor_maps.view.*
import java.io.ByteArrayOutputStream
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.cos
import kotlin.math.sin
Class
//class InfoWindowAdapter
inner class CustomInfoWindowGoogleMap(val context: Context) : GoogleMap.InfoWindowAdapter {
override fun getInfoContents(p0: Marker?): View? {
return null
}
#SuppressLint("InflateParams")
override fun getInfoWindow(p0: Marker?): View? {
val mInfoView = (context as Activity).layoutInflater.inflate(R.layout.reportvisor_maps, null)
val mInfoWindow: ReportPet? = p0?.tag as ReportPet?
mInfoView.title_window.text = mInfoWindow?.mTitleReport
mInfoView.date_ReportVisor.text = mInfoWindow?.mDate
mInfoView.description_ReportVisor.text = mInfoWindow?.mdescriptionReport
mInfoView.type_ReportVisor.text = mInfoWindow?.mTypeReport
try {
val imageReportVisor = mInfoView.findViewById<ImageView>(R.id.image_ReportVisor)
Glide.with(context).load(mInfoWindow?.mImageReport).into(imageReportVisor) // image
}catch (e: Exception){
Log.d("ERRORGLIDE","e: ${e.message}")
}
return mInfoView
}
}
then I call the marker in onMapReady:
//marker + infoWindow
mMap.setOnMarkerClickListener{
if (it.isInfoWindowShown){
it.hideInfoWindow()
}else{
it.showInfoWindow()
zoomMarker(it.position)
}
true
}
please help me!
Thanks
To implement AppGlideModule change in Build.Gradle:
implementation 'com.android.support:appcompat-v7' cambiar a esto:
implementation 'com.android.support:appcompat-v7:27.0.2'
In the Build.Gradle add plugin y dependencies:
apply plugin: 'kotlin-kapt'
dependencies {
...
compile 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
}
synchronize the gradle.
Add a class called MyAppGlideModule:
Pakage com.example.NombreApp
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
#GlideModule
class MyAppGlideModule: AppGlideModule(){}
Before continuing, it is important to mention that if you used Glide as a library, you should comment or delete the import of glide://import com.bumptech.glide.Glide.Now in the class (YourClass) that you want to use the AppGlide implement the module as follows:
GlideApp.with(context).load(url).into(imageView)
When finished rebuild the project:Build -> Rebuild Proyect
source: Youtube
Related
I am attempting to mock intent inside the function I made. Here is the function below
fun learningUnitTest(context: Context) {
val str = context.getString(R.string.app_name)
val intent = Intent(context, TodoFragment::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
} // it resulting null. how to mock this?
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
Log.d("AA", str)
Log.d("BB", pendingIntent.toString())
}
And this is my unit test file
import android.content.Context
import android.content.Intent
import android.util.Log
import com.example.todoapp.controller.worker.learningUnitTest
import io.mockk.*
import org.junit.Test
import org.mockito.Mock
import org.mockito.Mockito.*
class ExampleUnitTest {
private val FAKE_STRING = "FAKE"
#Mock
private lateinit var mockContext: Context
#Test
fun test_function() {
mockkStatic(Log::class)
mockkStatic(Intent::class)
mockContext = mock(Context::class.java)
every { Log.d(any(), any()) } returns 0
`when`(mockContext.getString(R.string.app_name))
.thenReturn(FAKE_STRING)
// every { Intent("aa") } returns mockIntent // Missing mocked calls inside every { ... }
learningUnitTest(mockContext)
verify(mockContext, times(1)).getString(R.string.app_name)
}
}
And not forgetting the dependencies which I used for testing, hopefully it has the correct version. I don't think I have to show any depedencies or any setup which are not related to the test file.
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'io.mockk:mockk:1.12.2'
testImplementation 'org.mockito:mockito-inline:3.8.0'
When I ran the test, it resulting an error like this
Method setFlags in android.content.Intent not mocked. See http://g.co/androidstudio/not-mocked for details.
java.lang.RuntimeException: Method setFlags in android.content.Intent not mocked. See http://g.co/androidstudio/not-mocked for details.
at android.content.Intent.setFlags(Intent.java)
at com.example.todoapp.controller.worker.WorkerUtilsKt.learningUnitTest(WorkerUtils.kt:97)
at com.example.todoapp.ExampleUnitTest.test_function(ExampleUnitTest.kt:35)
I even tried to mock using every for only the Intent::class.java accessing Intent("test") for the code like this every { Intent("aa") } returns mockIntent. But it still resulting an error.
I am new to selenium cucumber. I am getting an error on the feature file "no definitions found ..". But I have written the definitions. I also can execute the cucumber tests just fine.
Feature:
Feature: LOGIN_FEATURE
Scenario: login scenario
Given User is already on login page
When title is crom
Then user enters un and pw
Step definition:
package stepDefinition;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.*;
//import org.junit.Assert;
import static org.testng.Assert.assertTrue;
//import cucumber.api.java.en.Given;
public class loginStepDef {
WebDriver driver;
//#Then"^login should be unsuccessful$"
#Given ("^User is already on login page$")
public void User_already_on_login_page(){
System.out.println("givenM method started");
System.setProperty("webdriver.chrome.driver","C:\\src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://web.bettylist.com/user");
System.out.println("---Navigated to the URL.");
}
//#SuppressWarnings("deprecation")
#When("^title is crom$")
public void title_is_crom(){
System.out.println("whenM started.");
String title = driver.getTitle();
System.out.println("title" + title);
//Assert.assertEquals("Ff", title);
assertEquals("Log in | bettylist", title);
System.out.println("---validated the title before logging in.");
}
Runner:
package MyRunner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
//import cucumber.junit.Cucumber;
//import cucumber.api.CucumberOptions;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "workspace/Cucumber3/src/main/java/Features",
glue="stepDefinition"
//format = {"pretty", "html:target/Destination"}
//plugin = {"pretty","html:test-outout"},
//plugin = {"json:Folder_Name1/cucumber.json"},
//plugin = {"junit:Folder_Name/cucumber.xml"},
//dryRun = false
//monochrome = false,
//strict = false
)
public class TestRunner {
}
I am using ecliipse IDE. I also installed Natural plugin. How can I fix the no definitions found in the feature file?
package runnerFile;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(
features= {"src/test/resources/features"},glue= {"stepDefination"},
dryRun=false,
monochrome=true,strict=true
)
public class TestRunner extends AbstractTestNGCucumberTests{
}
mockito-1.10.19
powermock-mockito-1.7.1
powermock-1.7.4
junit 4.12
I have a class that has multiple constructors (java). Once constructor calls the other. I want to mock only 1 of the constructors (the one that is called from the other). I cannot change the code unfortunately - I am just testing it. Here is the class to be tested:
import java.io.File;
import java.sql.connection;
public class Foo {
public Foo (Connection connection){
this(connection, new File ());
}
public Foo (Connection connection, File file){
// do stuff
}
// other methods
}
Here is the test class I have written:
import java.io.File;
import java.sql.connection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.legacy.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Foo.class)
#PowerMockIgnore("javax.management.*")
public class FooTest {
#Test
public void testFoo() throws Exception {
Connection mockConnection = Mockito.mock(Connection.class);
Foo fooObj = Mockito.mock(Foo.class);
PowerMockito.whenNew(Foo.class).withArguments(Matchers.notNull(), Matchers.notNull()).thenReturn(fooObj);
Foo newFooObj = new Foo (mockConnection);
assertNotNull ("newFooObj should not be null", newFooObj);
}
}
The problem is that Foo(Connection) is not being entered. Is there something I am missing?
I tried your code with the latest 1.7.x version of Powermock (1.7.4) and it works as you wanted it to. So you might just need to upgrade a few minor versions.
java8 gradle2.3 groovy2.4.3
sourceSets {
main {
java { srcDirs = [] } // no source dirs for the java compiler
groovy { srcDir "src" } // compile everything in src/ with groovy
}
test{
java {srcDirs = []}
groovy{ srcDirs = ["src/test/java", "src/test/groovy"] }
}
}
ControllerServiceSpec.groovy: 18: unable to resolve class org.springframework.test.web.servlet.MockMvc
import info.thecodinglive.controller.TeamController
import info.thecodinglive.service.TeamService
import org.junit.runner.RunWith
import org.spockframework.runtime.Sputnik
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.http.HttpStatus.*
#RunWith(Sputnik)
class ControllerServiceSpec extends Specification{
def teamController = new TeamController()
def teamService = Mock(TeamService)
MockMvc mockMvc = standaloneSetup(teamController).build()
def setup(){
teamController.teamService = teamService
}
dependency
{compile 'org.codehaus.groovy:groovy-all:2.4.3'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'org.springframework', name: 'spring-test', version:"$springVersion"
testCompile group: 'org.springframework', name: 'spring-test-mvc', version:'1.0.0.M1'
testCompile "cglib:cglib-nodep:3.1"
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude group: "org.codehaus.groovy"
}
it works compile groovy/java but when i test controller
can't find dependencies