小编sin*_*ina的帖子

为什么hamcrest说字节0不等于int 0?

考虑使用标准JUnit断言和hamcrest的以下测试用例assertThat:

byte b = 0;
int i = 0;

assertEquals(b, i); // success
assertThat(b, equalTo(i)); // java.lang.AssertionError: Expected: <0> but: was <0>

if (b == i) {
    fail(); // test fails, so b == i is true for the JVM
}
Run Code Online (Sandbox Code Playgroud)

为什么会这样?对于JVM b == i来说true,这些值显然是相同的,因为为什么会hamcrest失败?

java junit hamcrest

22
推荐指数
2
解决办法
2547
查看次数

通过推送消息触发重新绘制检票口组件

我了解使用add(Component)of 方法重新绘制检票口组件的概念AjaxRequestTarget- 但我只能在客户端触发某些 ajax 事件时使用此方法。

但是我必须在不涉及任何用户交互的情况下重新绘制组件,所以我不能使用它。下一步是发现WebSocketBehavior它的关联方法onMessage()- 此消息再次获取类型WebSocketRequestHandler(扩展AjaxRequestTarget)的参数,我可以添加我的待重绘组件。但是这个方法似乎只有在客户端向服务器发送 websocket 消息时才会被调用。

最后我发现我可以通过打开一个IWebSocketConnection. Wicketinaction 在这篇博文 ( http://wicketinaction.com/2012/07/wicket-6-native-websockets/ ) 中建议使用以下代码行:

IWebSocketConnectionRegistry registry = new SimpleWebSocketConnectionRegistry();
Application application = Application.get(wsApplicationName);
IWebSocketConnection wsConnection = registry.getConnection(application, wsSessionId, wsPageId);

if (wsConnection != null && wsConnection.isOpen()) {
  try {
    wsConnection.sendMessage("test");
  } catch (IOException e) {}
}
Run Code Online (Sandbox Code Playgroud)

wsApplication、wsSessionId 和 wsPageIdonConnect在 WebSocketBehavior的方法中获取。

一般来说,这种方法是有效的 - 我可以将我的测试消息发送给客户端,并且它接收的正是这个文本。但是我找不到如何使用此方法触发组件重绘的方法。对此的任何建议将不胜感激 - 或者我最终完全错了?

wicket websocket

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

由Tycho surefire运行时OSGi捆绑包未激活

我有几个OSGi捆绑包,这些捆绑包是在Eclipse中使用正常的清单管理的依赖关系以及使用Maven Tycho进行的外部构建而构建的。

在Equinox上的Eclipse内部运行捆绑软件可以正常工作。用Tycho构建它们可以正常工作。

现在,我想使用Tycho Surefire来运行集成测试,为此,我创建了一个包含一些基本测试的简单测试包。被测试的捆绑包依赖于OSGi容器中存在的其他捆绑包以及一些较小的启动级别调整才能正常运行-就像我说的那样,当在Equinox上正常运行捆绑包时,捆绑包本身启动时就可以正常运行。

因此,为了模仿Tycho Surefire,我在测试包的pom.xml中指定了以下内容:

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>0.21.0</version>
            <configuration>
                <bundleStartLevel>
                    <bundle>
                        <id>org.hibernate.osgi</id>
                        <level>6</level>
                        <autoStart>true</autoStart>
                    </bundle>
                    <!-- plus a few more bundles in the real pom.xml -->
                </bundleStartLevel>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <configuration>
                <dependency-resolution>
                    <extraRequirements>
                        <requirement>
                            <type>eclipse-plugin</type>
                            <id>org.hibernate.entitymanager</id>
                            <versionRange>4.2.12.Final</versionRange>
                        </requirement>
                        <requirement>
                            <type>eclipse-plugin</type>
                            <id>org.hibernate.osgi</id>
                            <versionRange>4.2.12.Final</versionRange>
                        </requirement>
                        <!-- plus a few more bundles in the real pom.xml -->
                    </extraRequirements>
                </dependency-resolution>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

有趣的是,测试失败了。经过一些研究,我发现在失败的测试运行期间/之后如何访问OSGi控制台以进一步调查问题(运行tycho测试后的OSGi控制台)。

我的发现是,尽管OSGi容器中存在所有必需的捆绑软件(所有可传递衍生的捆绑软件和所有手动指定的捆绑软件),但只有具有独特特征<bundleStartLevel>的捆绑软件才被启动(当然还有OSGi-core-bundles)。

因此,考虑上面的例子中,我发现是,虽然双方org.hibernate.osgiorg.hibernate.entitymanager已得到解决,只有第一个是在“有效”状态。这显然使整个启动混乱,并且我的猜测是,如果捆绑包按预期启动,则测试可以正常运行。

当我查看“常规” Eclipse-OSGi-Launch配置时,有一个参数“ …

java eclipse-plugin tycho maven tycho-surefire-plugin

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

带有内部枚举类的 Eclipse AST 的奇怪结果

我正在试验 eclipse jdt AST 并且遇到了一种我无法解释的奇怪行为。

这是我的示例代码:

public static void main(String[] args) {
    StringBuilder content = new StringBuilder();
    content.append("class Foo {");
    content.append("    enum Bar {");
    content.append("        VALUE;");
    content.append("        int getValue() {");
    content.append("            return 4;");
    content.append("        }");
    content.append("    }");
    content.append("    int getValue() {");
    content.append("        return 42;");
    content.append("    }");
    content.append("}");

    ASTParser parser = ASTParser.newParser(AST.JLS13);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setSource(content.toString().toCharArray());

    CompilationUnit astNode = (CompilationUnit) parser.createAST(null);

    Visitor rtVisitor = new Visitor();
    astNode.accept(rtVisitor);

}

private static class Visitor extends ASTVisitor {

    @Override
    public boolean visit(TypeDeclaration node) {
        System.out.println(node);
        return …
Run Code Online (Sandbox Code Playgroud)

java abstract-syntax-tree eclipse-jdt

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

HTML5与Apache Wicket的可信和输入

我需要Apache Wicket应用程序中的可编辑文本.由于文本必须看起来非常"普通表",只有在用户双击文本后才进行编辑,依此类推,使用普通的TextFields并不是一个真正的选项.

所以我决定选择新的HTML5属性contenteditable,它可以很好地完成整个工作.使用以下标记和Java代码,我得到一个看起来像静态文本的标签,但在用户点击内部后,文本是可编辑的:

<div wicket:id="id" contenteditable></div>

...

item.add(new Label("id", "dummy content"));
Run Code Online (Sandbox Code Playgroud)

但是现在我显然需要在用户实际编辑文本时捕获一些事件,因为新文本应该存储回数据库中.在线手册建议使用,oninput因为它似乎更可靠(例如关于时间问题)onkeyup,onkeydown等等.

使用常规HTML5尝试该事件可以正常工作:

<div wicket:id="id" contenteditable oninput='alert("oninput");'></div>
Run Code Online (Sandbox Code Playgroud)

我现在的问题是,如何才能获得Wicket标签支持oninput?覆盖它并创建一个自定义标签将是一个非常好的解决方案(如果我真的必须),但为此我对Wicket来说太新了,知道从哪里开始以及如何创建正确的标记等等.

html5 wicket wicket-1.6

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