我创建了以下Chimpazee.java文件,内容如下:
class Primate {
public Primate() {
System.out.print("Primate-");
}
}
class Ape extends Primate {
public Ape(int fur) {
System.out.print("Ape1-");
}
public Ape() {
System.out.print("Ape2-");
}
}
public class Chimpazee extends Ape {
public Chimpazee() {
super(2);
System.out.print("Chimpazee-");
}
public static void main(String[] args) {
new Chimpazee();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用 Java 11 在 Windows 10 + PowerShell 上执行此文件时...
PS C:\projects\ocp-java-se\java-se-11\chapter8> java -version
java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server …Run Code Online (Sandbox Code Playgroud) 从 5.9.3升级junit-jupiter-engine到 5.10.0 后,我开始出现以下错误。我正在运行 Spring-Boot 3 应用程序(spring-boot-starter-parent 版本 3.1.2)。
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.187 s
[INFO] Finished at: 2023-07-25T12:27:39Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0:test (default-test) on project wa-search-api:
Error:
Error: Please refer to /home/runner/work/wa-search/wa-search/wa-search-api/target/surefire-reports for the individual test results.
Error: Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
Error: [ERROR] There was an error in the forked process
Error: TestEngine with ID 'junit-jupiter' failed to …Run Code Online (Sandbox Code Playgroud) 我想在一个Utils接受两个参数的类中创建方法,第一个是域类,第二个是来自域类的方法(作为引用传递)。这个Utils' 类有一个方法,该方法将创建该类的一个实例并在域类实例的范围内执行该方法。
例如,域类:
public class DomainClass {
public void dummyMethod() {}
}
Run Code Online (Sandbox Code Playgroud)
实用程序类:
public class Utils {
public static void execute(Class<?> clazz, Runnable referenceMethod) {
Object objInstance = clazz.getConstructor().newInstance();
// execute the 'referenceMethod' on the scope of 'objInstance'
}
}
Run Code Online (Sandbox Code Playgroud)
我想电话是这样的:Utils.execute(DomainClass.class, DomainClass::dummyMethod)。但是,这个场景有一些问题:
Utils类传递这个参数(现在我遇到了一些编译问题)?要将 BLOB 投影到 Oracle 中的 CLOB,我可以执行以下查询:
SELECT ent.ID, to_clob(ent.blob_string) from entity_1 ent;
Run Code Online (Sandbox Code Playgroud)
但是,我to_clob在 H2 中找不到等效的操作来查看我在 H2-console 中的数据。我怎么能做到这一点?
我担心提高源代码的可读性,它涉及通过将庞大的方法分解为更小的(简洁的)方法来减少它们的大小。所以,简而言之,假设我有一个非常单一的方法,可以做很多不同的事情,例如:
public void verHugeMethod(List<Person> people) {
for (Person person : people) {
totalAge += person.getAge();
totalHeight += person.getHeight();
totalWeight += person.getWeight();
// More calculations over class variables...
}
}
Run Code Online (Sandbox Code Playgroud)
我想将方法更改为:
public void calculateTotalAge(List<Person> people) {
for (Person person : people) {
totalAge += person.getAge();
}
}
public void calculateTotalHeight(List<Person> people) {
for (Person person : people) {
totalHeight += person.getHeight();
}
}
public void calculateTotalWeight(List<Person> people) {
for (Person person : people) {
totalWeight += person.getWeight();
}
}
// More …Run Code Online (Sandbox Code Playgroud) 我正在使用内存数据库(H2)进行集成测试,以便可以使用已知值填充存储库,并使用存储库初始化服务实现。这是我的考试课
@RunWith(SpringRunner.class)
@TestPropertySource("classpath:application-test.properties")
@SpringBootTest
public class ManufacturerServiceH2ImplTest {
@Autowired
private ManufacturerRepository manufacturerRepository;
@Autowired
ManufacturerServiceImpl manufacturerServiceImpl;
@Test
public void testManufacturerCreate() throws Exception {
//Create Manufacturer
Manufacturer manufacturer = new Manufacturer();
manufacturer.setManufacturerId("SSS");
manufacturer.setManufacturerName("WWW");
//Save Manufacturer in Inmemory
Manufacturer manufacturerInMemory = manufacturerRepository.save(manufacturer);
//Service Implementation
StResponse createManufacturer = manufacturerServiceImpl.createManufacturer(manufacturer);
//Compare the result
}
}
Run Code Online (Sandbox Code Playgroud)
服务实现应使用保存在内存数据库中的数据,并且很少执行业务验证。我在这里面临的问题是服务实现实际上是在考虑ManufacturerRepository实例,该实例指向实际的db(在这种情况下为postgres),而不是指向内存数据库。关于如何将指示厂商数据库指向内存数据库的ManufacturerRepository实例注入厂商serviceImpl服务实现的任何帮助