我想在运行 void 方法时抛出异常
when(booking.validate(any())).thenThrow(BookingException.builder().build());
Run Code Online (Sandbox Code Playgroud)
但我有一个编译错误:
Required type: T
Provided: void
reason: no instance(s) of type variable(s) T exist so that void conforms to T
Run Code Online (Sandbox Code Playgroud) I have this piece of code working fine on a project that uses RestTemplateBuilder 1.5.14
this.restTemplate = restTemplateBuilder
.setConnectTimeout(connectTimeout)
.setReadTimeout(readTimeout)
.requestFactory(new MyHttpComponentFactoryBuilder()
.build())
.build();
Run Code Online (Sandbox Code Playgroud)
After updating to RestTemplateBuilder 2.1.5 I have this piece of code:
this.restTemplate = restTemplateBuilder
.setConnectTimeout(Duration.ofMillis(connectTimeout))
.setReadTimeout(Duration.ofMillis(readTimeout))
.requestFactory(new MyHttpComponentFactoryBuilder().build().getClass())
.build();
Run Code Online (Sandbox Code Playgroud)
but when running the code I have a InvocationTargetException / NullPointerException that dissapears when deleting the line .requestFactory(new MyHttpComponentFactoryBuilder().build().getClass()) , but debugging new MyHttpComponentFactoryBuilder().build().getClass() is not null
I also tried with the solution proposed:
...
.requestFactory(new MyRequestFactorySupplier()) …Run Code Online (Sandbox Code Playgroud) 我有一个函数 ( hostelService.book) 返回一个 promise: returnPromise.resolve(response);
并且我做了这个测试:
const action = async () => {
await hostelService.book(id);
};
await expect(action).rejects.toThrow();
Run Code Online (Sandbox Code Playgroud)
但我有这个错误:
Matcher error: received value must be a promise
Run Code Online (Sandbox Code Playgroud) 我在 Junit 中有这段代码,在那里我清楚地将端口设置为 8888
when(clientUtils.getLinkUrl(eq(HOSTELS_MICROSERVICE.name()), eq(HOSTELS_MICROSERVICE.name()), anyMap()))
.thenReturn("http://localhost:8888/HOSTELS/HOSTELSMethods");
stubFor(com.github.tomakehurst.wiremock.client.WireMock.get("/HOSTELS/HOSTELS_LIST").willReturn(
aResponse().withStatus(200)
.withHeader("Content-Type", APPLICATION_JSON_VALUE)
.withBody(ResourceUtils.getResourceFileAsString ("__files/HOSTELS.json"))));
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时,我在这一行出现了这个错误:
stubFor(com.github.tomakehurst.wiremock.client.WireMock.get("/HOSTELS/HOSTELS_LIST").willReturn(..
Run Code Online (Sandbox Code Playgroud)
和错误:
wiremock.org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以在 Java 8 中将 LocalDate 转换为 OffsetDateTime。
例如假设我有这个 LocalDate:
1992-12-28
Run Code Online (Sandbox Code Playgroud)
然后我想把它转换成这样OffsetDateTime:
1992-12-28T00:00-03:00
Run Code Online (Sandbox Code Playgroud)
假设我们知道时区,例如 America/Santiago。
我想在测试类中创建一个 Lombok 类
@RunWith(SpringRunner.class)
@SpringBootTest
public class HostelIntegrationTest {
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(NON_NULL)
@EqualsAndHashCode
class User {
String property1;
Instant property2;
Integer property3;
}
Run Code Online (Sandbox Code Playgroud)
但我收到此编译错误:
此处不允许使用修饰符 static
我是Java 8的新手,具有以下表达式:
.map(mc -> mc.getName().getDefaultName())
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以将其替换为:
.map(TeleBadalonaCampaignType::getName::getDefaultName)
Run Code Online (Sandbox Code Playgroud) 我在玩笑中收到这个结果
result1 -> {
"partyRoleIdentifier": {
"internalEmployeeIdentifier": {
"id": "id-modified"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我做这样的比较:
expect(result).toBe('{\"partyRoleIdentifier\": {\"internalEmployeeIdentifier\": {\"id\": \"id-modified\"}}}');
Run Code Online (Sandbox Code Playgroud)
但我得到了这个结果:
Expected: "{\"partyRoleIdentifier\": {\"internalEmployeeIdentifier\": {\"id\": \"id-modified\"}}}"
Received: {"partyRoleIdentifier": {"internalEmployeeIdentifier": {"id": "id-modified"}}}
Run Code Online (Sandbox Code Playgroud) 我想在 Lombok 的构建器中使用自定义设置器并覆盖 1 个方法,如下所示
@SuperBuilder
public class User implements Employee {
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
private String username;
private String password;
public static class UserBuilder {
public UserBuilder password(String password) {
this.password = ENCODER.encode(password);
return this;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我有这个编译错误
Existing Builder must be an abstract static inner class.
Run Code Online (Sandbox Code Playgroud) java ×8
junit ×3
spring-boot ×3
java-8 ×2
javascript ×2
jestjs ×2
lombok ×2
mockito ×2
node.js ×2
spring ×2
typescript ×2
date ×1
datetime ×1
json ×1
lambda ×1
resttemplate ×1
wiremock ×1