相关疑难解决方法(0)

hamcrest测试总是失败

我正在使用hamcrest 1.3来测试我的代码.它只是一个骰子.我试图测试它以确保生成的数字小于13.我有一个打印语句打印生成的数字是什么.生成的数量始终小于13,但测试总是失败.有什么我做错了吗?

这是我正在测试的代码.

import java.util.Random;

public class Die {
    private int numSides;
    Random rand;

    public Die(int numSides){
        this.numSides = numSides;
        rand = new Random(System.currentTimeMillis());
    }

    public int roll(){
        return rand.nextInt(numSides) + 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的测试代码.

import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

public class DieTest {
    @Test
    public void testRoll() {
        Die x = new Die(12);    
        assertThat(x.roll(), is(lessThan(13)));
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:这是故障堆栈跟踪.

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
at …
Run Code Online (Sandbox Code Playgroud)

java junit hamcrest

43
推荐指数
6
解决办法
3万
查看次数

EclipseLink 2.7.0和JPA API 2.2.0 - 签名不匹配

运行由maven构建的具有以下依赖项的项目时:

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.7.0</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

我在运行时收到以下错误:

java.lang.SecurityException: class "javax.persistence.Cacheable"'s signer information does not match signer information of other classes in the same package
Run Code Online (Sandbox Code Playgroud)

javax.persistence-2.2.0工件已签名并包含javax.persistence.Cacheable.class注释,而eclipselink-2.7.0工件签名且包含相同的java类注释.

怎么解决这个问题?

编辑

用版本2.1.1替换javax.persistence artifact 2.2.0版修复了问题(这个没有签名),但我不确定这是正常情况.

java jpa eclipselink jpa-2.2

43
推荐指数
2
解决办法
1万
查看次数

签名者信息不匹配

我在日志文件中收到以下错误.

(java.lang.SecurityException:类"com.adventnet.snmp.snmp2.SecurityModelTable"的签名者信息与抛出的同一个包中其他类的签名者信息不匹配

事情就是当我在命令下运行时,它说jar验证了.

/usr/jdk/instances/jdk1.5.0/bin/jarsigner -verify -verbose Jarfile.jar
Run Code Online (Sandbox Code Playgroud)

如果jar文件已经过验证,那么这个问题怎么办?

java

18
推荐指数
2
解决办法
5万
查看次数

JUNIT 初始化错误

这是我的文件 AllTests 代码:

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
    ElementTests.class
})
public class AllTest {}
Run Code Online (Sandbox Code Playgroud)

元素测试.java

import org.junit.Test;
import pl.polsl.lab1.Model.*;
import static org.junit.Assert.*;
import org.junit.Test;

public class ElementTests {

    @Test
    public void properSymbolPlayerTest()
    {
        //given
        ElementOfBoard element = new ElementOfBoard();
        ElementOfBoard element2 = new ElementOfBoard();
        //when
        element.setSymbol(1);
        element.setSymbol(2);
        //then
        assertEquals('O', element);
        assertEquals('X', element2);
    }  

}
Run Code Online (Sandbox Code Playgroud)

我的错误

请问怎么解决啊 我正在使用 junit 4.11。我真的不知道初始化错误可能是什么。你能帮我吗?

我的堆栈跟踪:

org/hamcrest/SelfDescribing
java.lang.NoClassDefFoundError
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native …
Run Code Online (Sandbox Code Playgroud)

java junit

6
推荐指数
1
解决办法
5万
查看次数

'类“org.bouncycastle.asn1.ASN1Primitive”的签名者信息与同一包中其他类的签名者信息不匹配'使用Itext

我正在开发一个小工具来为PDF加水印,它适用于一些PDF,而其他一些崩溃

我正在使用iText库和 bouncycastle(依赖项)

pom.xml:

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.49</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

它在这一行(代码的第一行)崩溃

PdfReader reader = new PdfReader(src);
Run Code Online (Sandbox Code Playgroud)

使用以下堆栈跟踪:

Exception in thread "main" com.itextpdf.text.exceptions.InvalidPdfException: class "org.bouncycastle.asn1.ASN1Primitive"'s signer information does not match signer information of other classes in the same package
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:727)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:181)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:219)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
... <from here it points to my code>
Run Code Online (Sandbox Code Playgroud)

我已经做了一些谷歌搜索,有些人说可能问题是我在某处复制了这个bouncycastle …

java pdf spring itext maven

5
推荐指数
1
解决办法
6241
查看次数

在libgdx项目中启动android时出现AndroidStudio异常

在Android Studio 3.0.1中运行android gradle任务时出现异常。我的项目是使用libgdx构建的。我的桌面gradle任务运行得非常完美。

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':android:validateSigningDebug'.
Run Code Online (Sandbox Code Playgroud)

根本原因在哪里

Caused by: java.lang.SecurityException: class "org.bouncycastle.jcajce.provider.symmetric.IDEA$Mappings"'s signer information does not match signer information of other classes in the same package
Run Code Online (Sandbox Code Playgroud)

我绝对不知道如何解决这个问题。

libgdx android-studio-3.0

5
推荐指数
1
解决办法
2100
查看次数

Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配

我正在尝试使用 REST-Assured 和 JUnit5 在我的 Spring Boot 应用程序中编写一些集成测试,但是当我运行以下命令时:

@SpringBootTest(classes = ProductsApplication.class)
class ProductsApiTest {

  @Before
  public void setup() {
    RestAssured.baseURI = "http://localhost:8080/test/api/products";
  }

  @Test
  public void test1() {
    ValidatableResponse statusCode = given().when().get().then().statusCode(200);
  }
}
Run Code Online (Sandbox Code Playgroud)

出现一个令人讨厌的错误:

java.lang.SecurityException:类“org.hamcrest.Matchers”的签名者信息与同一包中其他类的签名者信息不匹配

请看一下我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    ...
    <dependencies>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        ...
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>   
        <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java junit integration-testing hamcrest spring-boot

5
推荐指数
1
解决办法
1938
查看次数

当我试图包含对模拟对象的期望时,这个SecurityException的原因是什么?

我正在尝试在测试中使用模拟对象.但是,当我尝试列出模拟对象的期望时,抛出相同的异常.
以下是异常的堆栈跟踪:

java.lang.SecurityException: class "org.hamcrest.TypeSafeMatcher"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(Unknown Source)
    at java.lang.ClassLoader.preDefineClass(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at …
Run Code Online (Sandbox Code Playgroud)

java junit mocking expectations

1
推荐指数
1
解决办法
4588
查看次数