Skip to content

Display geo location #5

@Tschasmine

Description

@Tschasmine

Display the geo location (longitude and latitude) for each table row in the infosystem.
Use PowerMock to write a unit test that mocks both, the TradingPartner object and the Nominatim web service:

testCompile "org.powermock:powermock-module-junit4:1.6.2"
testCompile "org.powermock:powermock-api-mockito:1.6.2"

Use the Nominatim Java API by adding the following dependency to your build.gradle file:
compile "fr.dudie:nominatim-api:3.3".
Using the Nominatim Java API:

NominatimClient jsonNominatimClient = new JsonNominatimClient(new DefaultHttpClient(), "some@email.com");
return jsonNominatimClient.search("searchString");

In order for Jacoco to pick up on the code coverage of a PowerMocked test, the classes need to be instrumented before the tests are run. Since Gradle does not support this yet, the following is needed in the build.gradle file:

task instrument(dependsOn: [classes, project.configurations.jacocoAnt]) {

	inputs.files classes.outputs.files
	File outputDir = new File(project.buildDir, 'instrumentedClasses')
	outputs.dir outputDir
	doFirst {
		project.delete(outputDir)
		ant.taskdef(
				resource: 'org/jacoco/ant/antlib.xml',
				classpath: project.configurations.jacocoAnt.asPath,
				uri: 'jacoco'
		)
		def instrumented = false
			if (file(sourceSets.main.java.outputDir).exists()) {
				def instrumentedClassedDir = "${outputDir}/${sourceSets.main.java}"
				ant.'jacoco:instrument'(destdir: instrumentedClassedDir) {
					fileset(dir: sourceSets.main.java.outputDir, includes: '**/*.class')
				}
				//Replace the classes dir in the test classpath with the instrumented one
				sourceSets.test.runtimeClasspath -= files(sourceSets.main.java.outputDir)
				sourceSets.test.runtimeClasspath += files(instrumentedClassedDir)
				instrumented = true
			}
		if (instrumented) {
			//Disable class verification based on https://github.com/jayway/powermock/issues/375
			test.jvmArgs += '-noverify'
		}
	}
}
test.dependsOn instrument

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions