我正在尝试让我的一个模拟对象在调用特定方法时抛出一个已检查的Exception.我正在尝试以下方法.
@Test(expectedExceptions = SomeException.class)
public void throwCheckedException() {
List<String> list = mock(List.class);
when(list.get(0)).thenThrow(new SomeException());
String test = list.get(0);
}
public class SomeException extends Exception {
}
Run Code Online (Sandbox Code Playgroud)
但是,这会产生以下错误.
org.testng.TestException:
Expected exception com.testing.MockitoCheckedExceptions$SomeException but got org.mockito.exceptions.base.MockitoException:
Checked exception is invalid for this method!
Invalid: com.testing.MockitoCheckedExceptions$SomeException
Run Code Online (Sandbox Code Playgroud)
看看Mockito文档,他们只使用RuntimeException,是否不可能使用Mockito从模拟对象中抛出已检查的异常?
虽然半年多以前就提出了类似的问题,但我想知道编写JRuby代码的最佳方法是什么,这取决于宝石,但也取决于Maven项目.Bundler似乎是Ruby社区的标准Maven工具,我更喜欢使用它,但看起来Bundler 不支持Maven依赖.
是gem install mvn:<groupId>:<artifactId>唯一真正的解决办法?我会把它放到Rakefile中吗?然后人们用rake而不是捆绑器来做他们所有的宝石安装吗?有没有人有其他建议来解决这个问题?谢谢.
而 Linux 上的 manenv似乎表明您可以在执行命令之前设置新的环境变量。不幸的是,当我在 Linux 系统上的文件的 shebang 中设置新变量时,该文件永远不会执行。
#!/usr/bin/env VAR1=foo bash
echo $VAR1
Run Code Online (Sandbox Code Playgroud)
当我在 CentOS 或 Ubuntu 机器上执行此文件时,它就放在那里。
$ ./shell-env.sh
<nothing happens>
Run Code Online (Sandbox Code Playgroud)
我觉得特别奇怪的是,它在带有 BSD 的 OS X 上运行得非常好env。
$ ./shell-env.sh
foo
$
Run Code Online (Sandbox Code Playgroud)
env这只是 BSD和 Linux之间的区别吗env?为什么 Linux 的手册页似乎说它的工作方式应该与 BSD 上的工作方式相同?
PS 我这里的用例是覆盖PATH变量,所以我可以尝试在系统上找到 a ruby,但它不在PATH.
先感谢您!
使用Spring-Context MANIFEST定义,我正在尝试component-scan搜索Spring注释bean的包.我的Spring XML配置看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<!-- Scans the classpath of this application for @Components to deploy as
beans -->
<context:component-scan
base-package="com.some.other.module.one,com.another.module.two" />
<context:annotation-config />
....
</beans>
Run Code Online (Sandbox Code Playgroud)
在MANIFEST中,我使用Spring注释导入包含类的包.但是,当我检查ApplicationContext时,它没有任何带注释的bean.
我相信这种情况正在发生,因为我们正在扫描的类路径是不同的捆绑包.这些bundle不直接导入包含Spring注释的类的包.令人困惑的是,为什么Spring没有选择从组件扫描开始的主包的类路径?在进行类路径扫描时,似乎正在使用每个bundle的类路径.有没有办法让类路径扫描使用扫描开始的包的类路径?
编辑
正如Danail Nachev在下面所说,当Spring执行类路径扫描时,它只发生在类路径发生的模块中.解决方法是使用:
@Configurationbean中.@Configurationbean 的XML文件.@Configurationbean中使用@Import导入其他配置文件.Require-Bundle在您的MANIFEST中确保您导入的配置可用.我相信我误解了捆绑器的工作方式,但从bundle install 文档中可以看出捆绑器将使用本地安装的系统宝石.
...
--system:安装到系统位置($ BUNDLE_PATH或$ GEM_HOME),即使该软件包以前安装在此应用程序的其他位置
...
--system选项是默认选项.使用--path选项后,将其传递回切换,如下所述.
我没有使用rbenv/rvm或任何其他Ruby版本管理器.我使用ChefDK作为我的主要开发环境,它带有Ruby和一堆预装的宝石.
Gemfile的全部内容,还没有Gemfile.lock.
source 'https://rubygems.org'
gem 'nokogiri', '1.6.3.1'
Run Code Online (Sandbox Code Playgroud)
当地的nokogiri安装
$ gem list --local | grep nokogiri
nokogiri (1.6.6.2, 1.6.3.1, 1.5.5)
Run Code Online (Sandbox Code Playgroud)
System Gem位置安装了nokogiri 1.6.3.1
$ echo $GEM_HOME
/Users/arthur/.chefdk/gem/ruby/2.1.0
$ find /Users/arthur/.chefdk/gem/ruby/2.1.0 | grep nokogiri | grep 1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/cache/nokogiri-1.6.3.1.gem
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/extensions/x86_64-darwin-12/2.1.0/nokogiri-1.6.3.1/mkmf.log
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.autotest
/Users/arthur/.chefdk/gem/ruby/2.1.0/gems/nokogiri-1.6.3.1/.editorconfig
...
Run Code Online (Sandbox Code Playgroud)
但是,当我运行bundle install时,它会尝试为nokogiri安装和编译libxml2.
$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using mini_portile 0.6.0
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following …Run Code Online (Sandbox Code Playgroud)