我目前正在研究Mockito框架,并且我使用Mockito创建了几个测试用例.但后来我读到的不是调用模拟(SomeClass的的.class)我可以使用@Mock和@InjectMocks-我需要做的唯一一件事情就是我的注释测试类@RunWith(MockitoJUnitRunner.class)或使用MockitoAnnotations.initMocks(this);的@Before方法.
但它不起作用 - 似乎@Mock不会起作用!这是我的2个代码修订版 - 一个使用注释,一个没有.
我究竟做错了什么?
public class ReportServiceImplTestMockito {
private TaskService mockTaskService; // This is the Mock object
private ReportServiceImpl service;
@Before
public void init(){
service = new ReportServiceImpl();
mockTaskService = mock(TaskServiceImpl.class);
service.setTaskServiceImpl(mockTaskService);
}
/// ...
Some tests
}
Run Code Online (Sandbox Code Playgroud)
正如我所说 - 这项工作很棒.但以下不会:
@RunWith(MockitoJUnitRunner.class)
public class ReportServiceImplTestMockito {
@Mock
private TaskService mockTaskService;
@InjectMocks
private ReportServiceImpl service;
// Some tests
}
Run Code Online (Sandbox Code Playgroud)
这是ReportServiceImpl班级:
@Service
public …Run Code Online (Sandbox Code Playgroud) 当我试图运行perl脚本(在我的centos 6机器上)时,我收到此消息:
Can't locate JSON.pm in @INC (@INC contains:
/usr/local/lib/perl5/5.10.1/x86_64-linux-thread-multi
/usr/local/lib/perl5/5.10.1
/usr/local/lib/perl5/site_perl/5.10.1/x86_64-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.1 .)...
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后,我发现我需要安装该模块; 但是,当我打字时:
sudo yum install perl-JSON
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
...
Setting up Install Process
Package perl-JSON-2.17-1.el5.noarch already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能运行该脚本?
我的perl版本是 v5.10.1
谢谢,
我需要阅读几个大的(200Mb-500Mb)XML文件,所以我想使用StaX.我的系统有两个模块 - 一个用于读取文件(使用StaX); 另一个模块('parser'模块)假设获取该XML的单个条目并使用DOM解析它.我的XML文件没有特定的结构 - 所以我不能使用JaxB.如何将"解析器"模块传递给我想要解析的特定条目?例如:
<Items>
<Item>
<name> .... </name>
<price> ... </price>
</Item>
<Item>
<name> .... </name>
<price> ... </price>
</Item>
</Items>
Run Code Online (Sandbox Code Playgroud)
我想使用StaX来解析该文件 - 但每个'item'条目都将传递给'parser'模块.
编辑:
经过多一点阅读 - 我想我需要一个使用流读取XML文件的库 - 但是使用DOM解析每个条目.有这样的事吗?
我想使用nagios来监控elasticsearch.基本上,我想知道弹性搜索是否已经完成.
我想我可以使用elasticsearch Cluster Health API(参见这里)
并使用我得到的"状态"(绿色,黄色或红色),但我仍然不知道如何使用nagios(nagios在一台服务器上,而elasticsearc在另一台服务器上).
还有另一种方法吗?
编辑: 我刚发现 - check_http_json.我想我会试一试.
我正在使用jpa,我有以下实体:
@Entity
@Table(name="favorites_folders")
public class FavoritesFolder {
private static final long serialVersionUID = 1L;
@Id
private String id;
@NotNull
@Size(min = 1, max = 50)
public String name;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(
name="favorites_products",
joinColumns=@JoinColumn(name="folder_id")
)
@Column(name="product_id")
@NotNull
private Set<String> productsIds = new HashSet<String>();
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是获取一组FavoritesFolder在其productsIds成员集中包含字符串"favorite-id" 的实体.
有谁知道如何在标准API中完成?
更新:
我认为以下sql应该做的伎俩,但我不知道怎么做,JPQL或者Criteria API:
select * from favorites_folders join favorites_products on favorites_folders.id = favorites_products.folder_id where favorites_products.product_id = 'favorite-id'
Run Code Online (Sandbox Code Playgroud) 我正在使用spring 3.1.2,我需要将一个json对象解析为POJO.这是我需要解析的json:
{
"Person" : {
"id" : "2"
},
"Dog" : {
"dateOfBirth" : "2012-08-20 00:00:00",
"price" : "10.00"
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将这个json对象(由两个对象组合)转换为一个POJO,这里是:
public class MyClass{
public MyClass(){}
public MyClass(String personsId, TimeStamp dogsDateOfBirth, BigDecimal dogsPrice){
.... // assign each parameter to the appropriate field
}
private String personsId;
private TimeStamp dogsDateOfBirth;
private BigDecimal dogsPrice;
//... Getters and Setters for each field
}
Run Code Online (Sandbox Code Playgroud)
为此,我使用了ObjectMapper mapper = new ObjectMapper();
Now,因为我有几个json对象,我的代码看起来像这样:
String json = ... ;// A json with several objects as …Run Code Online (Sandbox Code Playgroud) 我正在使用Postgres DB并进行迁移我正在使用Liquibase.我有一个包含以下列的ORDERS表:
ID | DATE | NAME | CREATOR | ...
Run Code Online (Sandbox Code Playgroud)
我需要添加一个新列,该列将保留上次修改订单的用户 - 此列应该是不可为空的,并且应该具有默认值,即CREATOR.对于新订单,我可以解决业务逻辑的默认值部分,但事情是我已经有了现有订单,我需要在创建新列时设置默认值.现在,我知道我可以在Liquibase中设置一个硬编码的默认值 - 但是有一种方法可以根据该表的其他一些列(对于每个实体)添加默认值.
我们使用与Jackson的JSON序列化来公开系统的内部状态以调试属性.
默认情况下,jackson不会序列化瞬态字段 - 但我也希望将它们序列化.如何序列化这些字段?
我知道的一种方法是为这些字段提供getter - 但我不想这样做,因为我有一些我不想被调用的getX方法(例如,有一些getter改变了对象国家).
我知道我可以创建一个注释,但我真的想避免它.
所以我的问题是:有没有办法设置杰克逊序列化所有对象字段?包括短暂的.
我有一个打包为war文件(包括几个jar文件)的Web应用程序.我注意到,当我运行mvn安装-这是编译的唯一的项目是那些谁已经改变了-那么它替换这些jar,单位为s war文件.
如果是这种情况 - 何时应该使用mvn clean install而不是简单地使用mvn install?
我想如果我改变任何资源而不是使用mvn clean install - 我是对的吗?
如果我是对的,那么每当我只改变课程时,mvn安装是否足够好?
我有一个我希望 spring 安排的方法 - 就此而言,我正在使用@Scheduled注释 - 更准确地说,我正在使用 cron 表达式。我的 cron 表达式位于名为 scheduler.properties 的属性文件中。当我将它用作占位符时@Scheduled(cron="${cron}")- 一切都很好;但我想使用 SpEL ( @Scheduled(cron="#{scheduler['cron']}")) ,但它不起作用 - 引发以下异常:java.lang.IllegalArgumentException: cron expression must consist of 6 fields (found 1 in #{scheduler['cron']})
我在这里做错了什么?
编辑:
这是我的属性文件中的 cron 表达式:cron=0 0/1 * * * ?
这是我得到的堆栈跟踪:
java.lang.IllegalArgumentException: cron expression must consist of 6 fields (found 1 in #{scheduler['cron']})
at org.springframework.scheduling.support.CronSequenceGenerator.parse(CronSequenceGenerator.java:233)
at org.springframework.scheduling.support.CronSequenceGenerator.<init>(CronSequenceGenerator.java:81)
at org.springframework.scheduling.support.CronTrigger.<init>(CronTrigger.java:54)
at org.springframework.scheduling.support.CronTrigger.<init>(CronTrigger.java:44)
at org.springframework.scheduling.config.ScheduledTaskRegistrar.afterPropertiesSet(ScheduledTaskRegistrar.java:188)
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:209)
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:1)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
at …
java ×7
json ×3
jackson ×2
spring ×2
annotations ×1
centos ×1
centos6 ×1
collections ×1
criteria-api ×1
cron ×1
dom ×1
jpa ×1
liquibase ×1
maven ×1
migration ×1
mocking ×1
mockito ×1
monitoring ×1
nagios ×1
perl ×1
pojo ×1
postgresql ×1
stax ×1
xml ×1