小编til*_*ias的帖子

assertThatThrownBy() 检查自定义异常的字段

如何使用assertJ 检查自定义异常中的特定字段值?

这是异常类:

public class SomeException extends RuntimeException {
    private final Set<Integer> something;

    public SomeException (String message, Set<Integer> something) {
        super(message);

        this.something = something;
    }

    public Set<Integer> getSomething() {
        return something;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的测试:

    assertThatThrownBy(() -> service.doSomething())
        .isInstanceOf(SomeException.class)
        .hasMessageStartingWith("SomeException has 1,2,3,4 in something field. I want assert that")
        . ??? check that SomeException.getSomething() has 1,2,3,4 ???
Run Code Online (Sandbox Code Playgroud)

问题是,如果我链接extracting() ,它会认为我正在使用Throwable。所以我无法提取字段内容

更新:

SomeException throwable = (SomeException) catchThrowable(() -> service.doSomething(

assertThat(throwable)
    .hasMessageStartingWith("extracting() bellow still think we're working with …
Run Code Online (Sandbox Code Playgroud)

java exception assertj

22
推荐指数
2
解决办法
3万
查看次数

Typescript alias with dot

I have following imports (in the same TS source file):

import {Vector as sourceVector} from "ol/source";
import {Vector} from "ol/layer";
Run Code Online (Sandbox Code Playgroud)

Here is how Vector is exported in ol/source:

export { default as Vector } from './source/Vector';
Run Code Online (Sandbox Code Playgroud)

And ol/layer:

export { default as Vector } from './layer/Vector';
Run Code Online (Sandbox Code Playgroud)

Is it possible to refactor imports somehow so it will look like this:

import {Vector as source.Vector} from "ol/source";
import {Vector as layer.Vector} from "ol/layer";
Run Code Online (Sandbox Code Playgroud)

Unfortunately I don't have any control over …

typescript typescript-typings openlayers-6

5
推荐指数
1
解决办法
690
查看次数

将 terraform 输出分配给环境变量

如何将 terraform 输出分配给环境变量?

假设我在main.tf中定义了以下输出

output "gce_public_ip" {
    value = element(concat(google_compute_instance.vm_instance.*.network_interface.0.access_config.0.nat_ip, list("")), 0)
}
Run Code Online (Sandbox Code Playgroud)

我想导出gce_public_ip,因此它将作为环境变量提供GCE_PUBLIC_IP

terraform terraform-provider-gcp

5
推荐指数
1
解决办法
2346
查看次数

Angular 6 多次为 Observable 调用 subscribe()

我有两个组件:NewItemComponent 和 ListComponent。当我在相应的组件内创建新项目时,我会通知 ListComponent 以便它可以刷新它的数据模型:

export class NewItemComponent implements OnInit {

  constructor(private itemService: ItemService, private notificationService: NotificationService) {
  }

  ngOnInit() {
  }

  createNewItem(item: Item) {
    this.itemService.persist(item).subscribe((response: Item) => {
      console.log(response);
      this.notificationService.notifyNewItemHasBeenCreated(response);
    });
  }
}


export class ListComponent implements OnInit {

  items: Item[];

  constructor(private listService: ListService, private notificationService: NotificationService) {
  }

  ngOnInit() {
    this.loadItems();

    this.notificationService.item$.subscribe((item) => {
      if (item != null) {
        this.loadItems();
      }
    })
  }

  loadItems(){
    this.istService.getItems().subscribe((data: Item[]) => {
      this.items= data;
      console.log(this.items);
    });
  }
}


@Injectable({
  providedIn: 'root'
}) …
Run Code Online (Sandbox Code Playgroud)

typescript angular

2
推荐指数
1
解决办法
2万
查看次数

@SpringBootTest 与 MapStruct 需要 Impl

我有以下测试:

@SpringBootTest(classes = {SomeService.class, DtoMapperImpl.class})
class SomeServiceTest {
Run Code Online (Sandbox Code Playgroud)

以及以下映射器:

@Mapper(componentModel = "spring")
public interface DtoMapper {
    EntityDto toDto(Entity entity);
}
Run Code Online (Sandbox Code Playgroud)

我不会更改包(这意味着DtoMapperImpl与DtoMapper位于同一包中)

一旦我将 Impl 更改为接口,我的测试就会失败:

@SpringBootTest(classes = {SomeService.class, DtoMapper.class})
class SomeServiceTest {
Run Code Online (Sandbox Code Playgroud)

引起:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“someService”的bean时出错:通过构造函数参数2表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“DtoMapper”类型的合格 bean:预计至少有 1 个符合自动装配候选资格的 bean。依赖注释:{}

您能建议解决这个问题的最佳方法吗?我正在使用 MapStruct 1.3.1.Final

java mapstruct spring-boot-test

2
推荐指数
1
解决办法
3207
查看次数