I recently moved to Roboelectric 3.0 and I cant get past a simple step to run a test which runs the following command:
#Config(sdk = 18, constants = BuildConfig.class)
#RunWith(RobolectricGradleTestRunner.class)
public class LegDetailActivityTest {
#Test public void testThatLegDetailActivityCanBeInjected() {
LegDetailsActivity activity =
Robolectric.buildActivity(LegDetailsActivity.class).create(bundle).get();
graph.inject(activity);
}
}
I receive the following error:
android.view.InflateException: XML file build/intermediates/res/merged/debug/layout/abc_screen_toolbar.xml line #-1 (sorry, not yet implemented): Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:299)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
My activity class is extended with AppCompatActivity.
My build.gradle has these dependencies:
testCompile 'junit:junit:4.12'
testCompile 'org.easytesting:fest:1.0.16'
testCompile 'com.squareup:fest-android:1.0.8'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
testCompile('org.robolectric:shadows-support-v4:3.0')
Has anyone experienced this issue?
The problem was somewhere with the v4 library. I solved it by excluding v4 in my build.gradle.
testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
Related
Facing isssue while integration with datastax with cassandra
gradle file :
plugins {
id 'org.springframework.boot' version '2.3.12.RELEASE'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
id 'org.sonarqube' version '3.2.0'
}
group = 'in.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
def javaDriverVersion ='4.14.1'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation ('org.springframework.boot:spring-boot-starter')
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-tomcat'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
}
implementation('org.springframework.boot:spring-boot-starter-jetty')
implementation('org.springframework.boot:spring-boot-starter-webflux')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
// datastax driver
implementation group: 'com.datastax.oss', name: 'java-driver-core', version: javaDriverVersion
implementation group: 'com.datastax.oss', name: 'java-driver-query-builder', version: javaDriverVersion
//implementation group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
implementation group: 'com.datastax.oss', name: 'native-protocol', version: '1.5.0'
annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: javaDriverVersion
//compileOnly group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: '4.14.1'
compileOnly group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
}
tasks.named('test') {
useJUnitPlatform()
}
#Data
#AllArgsConstructor
#NoArgsConstructor
#Entity(defaultKeyspace = "quest_test")
public class TestTable {
private UUID id;
private String name;
}
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.mapper.annotations.Select;
#Dao
public interface TestTableDao {
#Select
TestTable findById();
}
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory;
import com.datastax.oss.driver.api.mapper.annotations.Mapper;
#Mapper
public interface TestTableMapper {
#DaoFactory
TestTableDao testTableDao();
}
getting error
Unable to load class 'com.datastax.oss.driver.api.mapper.entity.naming.GetterStyle'.
i tried to interaction with different project also but still not able to solve issue
. for testing part i added library mappstruct which is generation code on compile time
With drivers 4x+, you need to declare an annotation processor for the mappers code to be generated at build time.
Gradle file
dependencies {
annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: javaDriverVersion
compile group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
}
Documentation
Here more code to work with Driver 4x
You might be interested in the full-fledged Spring PetClinic application running with your technical stack.
I have come across two different variations of syntax to exclude a transient dependency in gradle
One uses name and another uses module. Which one is correct?
For eg:
name:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.19'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('org.springframework.boot:sprin g-boot-starter-web') {
exclude group: 'org.springframework', name: 'spring-context'
}
}
OR module:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.springframework', name: 'spring-context', version: '5.3.19'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('org.springframework.boot:sprin g-boot-starter-web') {
exclude group: 'org.springframework', module: 'spring-context'
}
}
The current documentation (7.4.2) shows module:
https://docs.gradle.org/7.4.2/userguide/dependency_downgrade_and_exclude.html
implementation('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections', module: 'commons-collections'
}
name is probably a legacy naming. Go with what the current documentation has, module.
When use this configuration I receive the initializationError of the JUnit Vintage:
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
But with this configuration #RunWith annotation isn't resolved:
testImplementation (group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.7.0-M1'
}
How can I correctly exclude the JUnit Vintage module?
You just need to remove the version number from the exclude specification (as that would exclude a particular version that is not used anyway):
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' // <- No version
}
}
test {
useJUnitPlatform()
}
It seems that for exclude you don't use group and name as parameters. You use group and module:
testImplementation (group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine', version: '5.7.0-M1'
}
And as already pointed by Bjørn Vester you don't need to specify the version.
Im attempting to run my spring app as a jar, but i get the below error
java.io.FileNotFoundException: class path resource [org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.class] cannot be opened because it does not exist
It runs fine from intelij(as in my main class can runs using the play button). I find the file under project structure --> Libraries and under external libraries (albeit depracted)
Ive tried to look into it, but everywhere (list of examples below) seem to talk about xml files instead of a class
Spring ClassPathResource - cannot be opened because it does not exist
Class path resource cannot be opened because it does not existHow to avoid "class path resource [...] cannot be opened because it does not exist" in a spring boot application?
java.io.FileNotFoundException: class path resource can't be opened
java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
My gradle file:
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'war'
id 'groovy'
// id 'java'
}
war {
enabled = true
}
jar {
manifest {
attributes 'Main-Class': 'co.za.ebucks.HandlingRewardsFormSubmission'
}
}
group = 'co.za.ebucks'
version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
ext {
seleniumVersion = '3.141.59'
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
test {
useTestNG()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// implementation 'org.springframework.session:spring-session-core'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework:spring-messaging'
implementation 'org.springframework.integration:spring-integration-file'
implementation group: 'org.webjars.bower', name: 'angular-ui-router', version: '0.2.8'
implementation group: 'org.webjars', name:'angularjs', version: '1.3.0-beta.11'
implementation group: 'org.webjars', name: 'bootstrap', version: '3.1.1-1'
// implementation 'org.webjars.bower:angular-ui-router'//, version: '1.0.20'
implementation 'commons-io:commons-io'//, version: '2.4'
implementation 'org.apache.commons:commons-dbcp2'//, version: '2.7.0'
implementation 'org.hibernate.validator:hibernate-validator'//, version: '6.1.2.Final'
// implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'//, version: '2.4.1'
implementation 'javax.servlet:javax.servlet-api'//, version: '4.0.1'
// compile group: 'org.apache.tomcat', name: 'tomcat-jni', version: '9.0.33'
implementation group: 'de.codecentric', name: 'spring-boot-admin-starter-client', version: '2.2.2'
implementation group: 'de.codecentric', name: 'spring-boot-admin-server', version: '2.2.2'
implementation group: 'org.testng', name: 'testng', version: '7.1.0'
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0'
implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
implementation group: 'com.google.guava', name: 'guava', version: '28.1-jre'
implementation group: 'cglib', name: 'cglib', version: '3.3.0'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.10'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
implementation "org.seleniumhq.selenium:selenium-support:${seleniumVersion}"
implementation group: 'io.appium', name: 'java-client', version: '7.3.0'
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: "${seleniumVersion}"
implementation group: 'org.seleniumhq.selenium', name: 'selenium-server', version: "${seleniumVersion}"
implementation group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: "${seleniumVersion}"
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'
testImplementation group: 'org.testng', name: 'testng', version: '7.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
And what Im sure is the class in question:
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
#Configuration
#EnableWebSocketMessageBroker
class WebSocketDefaultConfig extends AbstractWebSocketMessageBrokerConfigurer {
#Override
void configureMessageBroker(MessageBrokerRegistry config) {
// config.enableStompBrokerRelay("/topic/", "/queue/");
config.enableSimpleBroker("/topic/", "/queue/");
config.setApplicationDestinationPrefixes("/app");
}
#Override
void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/tailfilesep")
// .setAllowedOrigins("*")
// .setHandshakeHandler(new DefaultHandshakeHandler())
.withSockJS()
}
}
Kindly assist me, this has passed frustration. Why is that class not in the jar?
The only thing that worked was creating a new project - copy and pasted all the code, build files everything... lol and its fine.
Intelij corruption somewhere along the line
While trying to connect to Spring Websocket with SockJS, I am getting an error
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.springframework.web.socket.sockjs.SockJsException:
Uncaught failure in SockJS request, uri=http://localhost:8083//subscribe/info/771/nay07fet/websocket;
nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException:
WebSocket handshake failure; nested exception is java.lang.ClassCastException:
org.eclipse.jetty.websocket.jsr356.server.ServerContainer cannot be cast
to org.apache.tomcat.websocket.server.WsServerContainer
From online I figured out that I shall disable Tomcat in Classpath to overcome it, but no matter how I try, I can not get rid of Tomcat.
How I can reliably exclude tomcat from any project? Note that I found it in several places.
My current Dependency tree is here: http://pastebin.com/pH1iQejd
and it contains some tomcat. I need to get rid of everything that might cause that type confusion.
Here's my gradle.build (I tried some exlcudes but without success):
group 'com.company'
if (!hasProperty("buildNumber")) {
version "1.0.0-SNAPSHOT"
} else {
version "1.0.${buildNumber}-SNAPSHOT"
}
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
classpath("gradle.plugin.com.boxfuse.client:flyway-release:4.0.1")
classpath fileTree(dir: 'libs', include: '*.jar')
classpath fileTree(dir: 'src/main/resources/db/migration', include: '*.sql')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}
}
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-jetty") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa"){
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-websocket")
// http://mvnrepository.com/artifact/org.springframework.security/spring-security-core
compile group: 'org.springframework.security', name: 'spring-security-core', version: '4.1.0.RELEASE'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
compile group: 'com.google.code.gson', name: 'gson', version: '2.5'
compile group: 'com.rabbitmq', name: 'amqp-client', version: '3.5.6'
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
compile("org.springframework:spring-messaging")
compile 'org.springframework.amqp:spring-rabbit:1.5.5.RELEASE'
compile("com.h2database:h2")
compile 'org.quartz-scheduler:quartz:2.2.1'
compile group: 'joda-time', name: 'joda-time', version: '2.3'
//compile("com.npspot:jtransit-light:1.0.6")
compile("io.fastjson:boon:0.33")
compile fileTree(dir: 'libs', include: '*.jar')
// end::actuator[]
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile("org.springframework.boot:spring-boot-starter-test")
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: 'spring-boot-starter-logging'
runtime.exclude module: "spring-boot-starter-tomcat"
runtime.exclude module: 'spring-boot-starter-logging'
}
test {
reports {
junitXml.enabled = true
html.enabled = false
}
}
springBoot {
executable = true
}
I was facing this problem as well. I solved it by adding the exclude clause to the websocket dependency, i.e.:
compile("org.springframework.boot:spring-boot-starter-websocket") {
exclude module: "spring-boot-starter-tomcat"
}
After this, I realized it wasn't necessary to have the exclusion on all the other ones; it's only necessary on starter-web and starter-websocket.