小编heu*_*eug的帖子

Spring 单元测试:使用 @SpyBean 模拟 void 方法:获取该 bean 的 NullPointerException 除非我使用 @Mock 代替

我试图让 @SpyBean 或 @MockBean 在此测试中工作,就像它们在我的所有其他测试中工作一样。这里唯一的区别是此测试使用活动配置文件,因为它模拟了一些 AWS 库

如果我使用 SpyBean,我不必实例化该类,我已经在下面看到了无数与我的类似的示例,它们似乎工作得很好。

我正在测试的单元:

@Component
public class SqsAdapter {

    @Autowired
    QueueMessagingTemplate queueMessagingTemplate;

    @Autowired
    MyProcessor processor;

    @SqsListener("${queue.name}")
    public void onEvent(String message) {
        if (!StringUtils.isEmpty(message)) {
            processor.process(message);
        } else { 
            log.error("Empty or null message received from queue");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

以及一个期望 process(...) 被调用的简单单元测试:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@ActiveProfiles("local")
public class SqsAdapterTest {

    @Autowired
    AmazonSQSAsync amazonSQS;

    @SpyBean
    MyProcessor processor;

    @InjectMocks
    SqsAdapter adapter;

    @Test
    public void testOnEvent() {
        doNothing().when(processor).process(any()); // <---- process() is void
        String event = "royale …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing mockito spring-bean

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

CSS 过渡和汉堡包转换 --&gt; 点击 X(使用手写笔)

我有一个用于移动断点的菜单汉堡包“图标”。我将它设置为 3 行,我希望它们转换为 X(这将关闭菜单)。

我希望顶部栏旋转 45 度,中间栏消失,底部栏以其他方式旋转 45 度。然后顶部和底部栏将向上移动并创建一个 X

截至目前......它只在我按住鼠标时才动画。为什么会这样?我只需要动画在点击时自行完成。

html:

<a class="navbar-item-link" "javascript:void(0)" >
    <div class="hamburger-icon"><span></span></div>
</a>
Run Code Online (Sandbox Code Playgroud)

手写笔:

.hamburger-icon
    &:before, &.hamburger-icon span, &:after
    content ''
    display block
    height 2px
    width 20px
    background-size 100%
    background rgba(255,255,255,0.5)
    margin 6px auto 7px auto
    transition all 0.2s linear

    &:active
        &.hamburger-icon span
            background-color transparent
        &:before
            transform rotate(45deg)
            top -10px
            height 2px
            background rgba(255,255,255,0.5)
            width 30px
        &:after
            transform rotate(-45deg)
            bottom -10px
            height 2px
            background rgba(255,255,255,0.5)
            width 30px
Run Code Online (Sandbox Code Playgroud)

css animation transition transform stylus

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

如何仅使用命令行将环境变量传递给 gradle 包装器构建?

我正在尝试使用严格的命令行命令在本地传递 env 变量。在部署时,这些变量被传递到 docker 容器中,但在本地运行时,它们不存在,需要在本地设置。

他们需要在提交之前删除,因为它们是访问密钥,所以我不希望它们在 repo 中公开。这就是为什么在本地运行测试(没有 IDE)需要一个传递这些变量的命令。

我已经试过了:

./gradlew clean build -Dspring.profiles.active=local -DMY_ENV_VAR1=xxxxxx -DMY_ENV_VAR2=xxxxxx
Run Code Online (Sandbox Code Playgroud)

它似乎不起作用。我找不到构建命令选项的文档,但我认为这是您传递它们的方式。我在这里做错了什么?还是不可能?

java spring command-line environment-variables gradle

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