Skip to content

Instantly share code, notes, and snippets.

View babjo's full-sized avatar
🎯
Focusing

Chanhyeong Lee babjo

🎯
Focusing
View GitHub Profile
// global
var myApp = myApp || {};
// namespaces
myApp.routers = myApp.routers || {};
myApp.model = myApp.model || {};
myApp.model.special = myApp.model.special || {};
var testModule = (function () {
var myPrivateVar, myPrivateMethod;
// A private variable
myPrivateVar = 0;
// A private function
myPrivateMethod = function(foo) {
console.log(foo);
};
return {
// A public variable
class FakeBlogRepository implements BlogRepository {
private Map<String, List<Post>> data = new HashMap<>();
private long lastPostId = 0L;
public long save(long userId, Post post) {
lastPostId++;
post.setId(lastPostId);
List<Post> posts = data.get(userId);
class AuthClientImpl implements AuthClient {
public long verifyToken(String token) {
String rawJson = decrpyt(token);
User user = deserialize(rawJson);
return user.getId();
}
private String decrpyt(String token) { ... }
private User deserialize(String rawJson) { ... }
}
public class BlogService {
public BlogService(AuthClient authClient, BlogRepository repository) {
this.authClient = authClient;
this.repository = repository;
}
public AddPostResponse addPost(AddPostRequest request) {
// verifyToken 메소드 파라미터 추가
// 리턴 값이 User 객체로 변경
public class BlogServiceTest {
@Mock
private AuthClient authClient; // mock 객체생성
@Mock
private BlogRepository blogRepository; // mock 객체생성
@Test
public void addPost() {
public class BlogServiceTest {
@Test
public void addPost() {
// given
AuthClient authClient = ...
BlogRepository blogRepository = ...
BlogService service = new BlogService(authClient, blogRepository); // 생성자로 협력 객체 주입
AddPostRequest request = ...
public class SmallClass1 {
private Collaborator collaborator1;
public void doSomething(){
...
}
}
public class SmallClass2 {
private Collaborator collaborator2;
public void doSomething(){
...
public class BigClass {
private Collaborator collaborator1;
private Collaborator collaborator2;
private Collaborator collaborator3;
private Collaborator collaborator4;
private Collaborator collaborator5;
....
public void doSomething(){
...
public class ClassA {
...
public void methodA() { // changed
...
}
}
public class ClassB {
...
public void methodB() { // Oh, not affected!
...