Skip to content

Instantly share code, notes, and snippets.

@making
Forked from megascus/gist:0ff833fbabac25c7cb9c
Last active August 29, 2015 14:03
Show Gist options
  • Save making/30684220dd72d91f483a to your computer and use it in GitHub Desktop.
Save making/30684220dd72d91f483a to your computer and use it in GitHub Desktop.
public class SomeService {
//これをいれかえたい。
@Autowired
SomeRepository someRepository;
//
//
//
}
@Repository
public class SomeRepositoryImpl implements SomeRepository {
//いろいろな本番処理
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SomeServiceTest {
@Autowired
SomeService someService;
@Autowired
SomeRepository someRepository;
@Test
public void testHoge() throws Exception {
System.out.println(someRepository); // こいつはMock
System.out.println(someService);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.example.repository.SomeRepository" />
</bean>
<bean class="com.example.service.SomeService"/>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment