假设我想从我的IDE(Intellij IDEA或eclipse)4000 JUnit测试手动运行; 前1000次测试运行非常顺利(比如他们需要3分钟全部1000次),但测试1001单独使用超过30分钟.有没有办法可以跳过测试1001(当它仍在运行时)并让测试1002(和其他人)继续前进.我不想@Ignore测试1001并重新运行套件,因为我已经有测试1-1000的答案; 我也不想选择1001-4000测试,因为它需要太多时间.
我会使用某种按钮 - 跳过电流测试 - 可以在测试运行时按下.
如果不存在此类功能,IDE开发人员或JUnit开发人员需要对其进行增强吗?
我想检查不同平台之间的SOAP互操作性; 我是一名Java程序员,特别不懂C#.
我在C#中做了什么:
转移对象:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
[XmlRoot]
public class Pack
{
private int id;
private string name;
public Pack()
{
}
public Pack(int anId, string aName)
{
this.id = anId;
this.name = aName;
}
public void setId(int anId)
{
this.id = anId;
}
public int getId()
{
return id;
}
public void setName(string aName)
{
this.name = aName;
}
public string getName()
{
return name;
}
}
Run Code Online (Sandbox Code Playgroud)
网络服务:
using System; …Run Code Online (Sandbox Code Playgroud) 假设我们有以下代码:
@Entity
public class User {
@Id
private String name;
@OneToOne(cascade = CascadeType.ALL)
private Address address;
//getters and setters
}
@Entity
public class Address {
@Id
private int id;
private String street;
//getters and setters
}
@Stateless
//@Service
public class UserLogicClass {
@PersistenceContext
//@Autowired
private EntityManager entityManager;
public void logicOnUser(User user) {
if(logicOnAddress(user.getAddress()) {
otherLogicOnUser(user);
}
}
public boolean logicOnAddress(Address address) {
//
entityManager.find(address);//address becomes managed
//
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
//@Transactional(propagation = Propagation.REQUIRES_NEW)
public void otherLogicOnUser
//
entityManager.find(user);/*without annotation, user is …Run Code Online (Sandbox Code Playgroud) 假设有以下代码:
@SuppressWarnings("unchecked")
public static <T> T implicitCaster(Class<T> cls, Object o) {
return (T) o;
}
public static <T> T reflectionCaster(Class<T> cls, Object o) {
return cls.cast(o);
}
Run Code Online (Sandbox Code Playgroud)
代码在两种情况下都按预期工作,但在基元中有以下异常:
public static void main(String[] args) {
System.out.println(implicitCaster(int.class, 42));
System.out.println(reflectionCaster(int.class, 42));
}
Run Code Online (Sandbox Code Playgroud)
第一个调用按预期工作,但第二个调用抛出java.lang.ClassCastException.
这是一个不考虑自动装箱的角落案例吗?或者在这种情况下,反射铸造是否不可能提供自动装箱?或者是否有其他原因导致这种不一致?
编辑:调用此代码按预期工作:
public static void main(String[] args) {
System.out.println(implicitCaster(Integer.class, 42));
System.out.println(reflectionCaster(Integer.class, 42));
}
Run Code Online (Sandbox Code Playgroud) 在 Intellij IDEA 中,在方法中,您可以编写如下内容:
myNewMethod(someParam);
Run Code Online (Sandbox Code Playgroud)
然后,如果你去的光标myNewMethod,然后Alt+ Enter(或Command+Enter在Mac),你可以选择Create method 'myNewMethod',这将创建一个与预期的参数和返回值类型的新方法。
问题是这个新方法是在方法之后立即创建的,而不是在最后。我想在课程结束时生成它。
例如,我有一个公共方法,我按顺序生成了 3 个方法:
public methodPublic() {
myGenerated1();
myGenerated2();
myGenerated3();
}
Run Code Online (Sandbox Code Playgroud)
它最终会生成它们:
public methodPublic() {
myGenerated1();
myGenerated2();
myGenerated3();
}
private void myGenerated3() { ... }
private void myGenerated2() { ... }
private void myGenerated1() { ... }
Run Code Online (Sandbox Code Playgroud) 我有一个查询应该根据各种参数进行过滤;这些参数之一是列表。如果列表中有条目,则应该根据条目进行过滤;但如果列表为空/空,则不应对该字段进行任何过滤。
我的想法是这样的:
@Query("select a from Alert a where a.date >= :startDate " +
"and (((:countryIds) is null) or a.countryId in (:countryIds)) " +
"and (((:typeIds) is null) or a.siteTypeId in (:typeIds)) ")
List<Alert> findBy(@Param("startDate") Date startDate,
@Param("countryIds") Set<Long> countryIds,
@Param("typeIds") Set<Long> typeIds);
Run Code Online (Sandbox Code Playgroud)
发送 null List 会抛出 NPE;发送一个空列表会生成以下 SQL,这是无效的
where alert0_.date >= '2018-01-01' and
((1, 123) is null or alert0_.countryId in (1, 123))
Run Code Online (Sandbox Code Playgroud)
我也尝试过在 JPQL 中使用and (((:countryIds) is empty) or a.countryId in (:countryIds)),但在尝试编译 JPQL(在应用程序启动时)时它也不起作用:Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: ??? is …
假设以下场景
sealed trait Status
case object Active extends Status
case object Inactive extends Status
@scala.deprecated("deprecated because reasons")
case object Disabled extends Status /
Run Code Online (Sandbox Code Playgroud)
考虑到Disabled对象无法被删除并且val status: Status = getStatus存在以下问题之一:
status match {
case Active => ???
case Inactive => ???
}
Run Code Online (Sandbox Code Playgroud)
status match {
case Active => ???
case Inactive => ???
case Disabled => ???
}
Run Code Online (Sandbox Code Playgroud)
status match {
case Active => ???
case Inactive => ???
case _ => ???
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下可以实现类型安全穷举匹配吗?
这是一个非常流行的概念:Ioc(控制反转).我已经使用这个概念很长一段时间了.通常我会使用DI(而不是服务定位器)方法在我的代码中实现IoC.以下是我对IoC的理解.
如果classA依赖于classB,如果它在其中声明了classB的实例.它依赖于classB,由于某种原因(我稍后会谈到),不好,因此我们使用DI来解决这个问题.所以现在我们有一个名为IClassB的接口,它将在classA的构造函数中传递(我在这里采用构造函数注入,为了说明).这里是代码:
public class ClassA
{
IClassB _classBObj = null;
public ClassA(IClassB classBObj)
{
_classBObj = classBObj;
}
public void UseClassBMethod()
{
this._classBObj.classBMethod();
}
}
public class ClassB:IClassB
{
public void classBMethod()
{
//Some task carried out by classB.
}
}
public interface IClassB
{
void classBMethod();
}
Run Code Online (Sandbox Code Playgroud)
这里有代码使它运行:
class Program
{
static void Main(string[] args)
{
//This code is outside of class A and hence declaring
//object of ClassB is not dependency
ClassA classA=new ClassA(new ClassB);
classA.UseClassBMethod();
}
} …Run Code Online (Sandbox Code Playgroud) architecture design-patterns dependency-injection inversion-of-control
根据我的理解,这不是使用构思插件在Intellij中打开使用Maven构建的项目的最佳方法,即通过调用:
mvn idea:idea
Run Code Online (Sandbox Code Playgroud)
但是直接打开pom文件(Intellij有Maven的默认插件); 同样的事情,对于日食.
你能提供一些关于为什么这是一种更好的方法的论据吗?
假设有腿动物有一个特征:
trait Legged {
val legs: Int
def updateLegs(legs: Int): Legged
}
Run Code Online (Sandbox Code Playgroud)
有两种这样的有腿的动物:
case class Chicken(feathers: Int, legs: Int = 2) extends Legged {
override def updateLegs(legs: Int): Legged = copy(legs = legs)
}
case class Dog(name: String, legs: Int = 4) extends Legged {
override def updateLegs(legs: Int): Legged = copy(legs = legs)
}
Run Code Online (Sandbox Code Playgroud)
在农场里还有这些动物的持有人
case class Farm(chicken: Chicken, dog: Dog)
Run Code Online (Sandbox Code Playgroud)
以及一种通过添加一条额外的腿来变异所有有腿动物的通用方法
def mutate(legged: Legged): Legged = legged.updateLegs(legged.legs + 1)
Run Code Online (Sandbox Code Playgroud)
问题是如何在 上实现一个方法,Farm以便将mutate: Legged => Legged函数作为参数并将其应用于所有 …
java ×7
jpa ×2
scala ×2
spring ×2
architecture ×1
autoboxing ×1
c# ×1
casting ×1
eclipse ×1
ejb ×1
hibernate ×1
ide ×1
junit ×1
maven ×1
reflection ×1
soap ×1
testing ×1
transactions ×1
web-services ×1