我安装并配置了自己的Gerrit服务器.我使用web gui为Gerrit创建了一个存储库.我能够使用"git"命令成功克隆这个空的存储库,所以配置似乎没问题.接下来,我:
配置我的访问:git config --global user.email ...
,git config --global user.name ...
,
添加的远程:git add remote origin myUser@myGitHost:29418/project.git
,
创建并提交文件:git add file
,git commit -m "first commit"
.
到现在为止还挺好.
但是,当我尝试将其推送到我的仓库时,我得到输出:
myUser@myGitHost:~/project$ git push origin master
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 525 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://myUser@myGitHost:29418/project.git
! [remote …
Run Code Online (Sandbox Code Playgroud) 我对Mockito并不陌生,但是这次我在工作中发现了一个有趣的案例。希望您能帮助我。
我需要注入模拟以更改测试过程中的某些方法行为。问题是,bean结构是嵌套的,并且此bean位于其他bean内部,无法通过测试方法访问。我的代码如下所示:
@Component
class TestedService {
@Autowired
NestedService nestedService;
}
@Component
class NestedService {
@Autowired
MoreNestedService moreNestedService;
}
@Component
class MoreNestedService {
@Autowired
NestedDao nestedDao;
}
@Component
class NestedDao {
public int method(){
//typical dao method, details omitted
};
}
Run Code Online (Sandbox Code Playgroud)
因此,在我的测试中,我希望调用NestedDao.method返回模拟的答案。
class Test {
@Mock
NestedDao nestedDao;
@InjectMocks
TestedService testedSevice;
@Test
void test() {
Mockito.when(nestedDao.method()).thenReturn(1);
//data preparation omitted
testedSevice.callNestedServiceThatCallsNestedDaoMethod();
//assertions omitted
}
}
Run Code Online (Sandbox Code Playgroud)
我试图做一个initMocks:
@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
Run Code Online (Sandbox Code Playgroud)
还要在我的测试类上添加注释:
@RunWith(MockitoJUnitRunner.class)
Run Code Online (Sandbox Code Playgroud)
总是从方法获取空指针或错误答案(未模拟)。
我想这是嵌套调用错误,因此无法模拟此Dao。我也读过@InjectMocks只适用于setter或构造函数注入,这是我想念的(在私有字段上只是@Autowire),但是当我尝试时它没有起作用。
你猜我在想什么吗?;)