#test

A bad system design can lead to much hard work. In order to increase the unit tests coverage, I recently started to work on writing unit tests for some classes. One of the case is I want to test a method as follow:

1
2
3
4
5
6
7
8
public final ReturnType getMethod (SomeRequest someRequest) {
AnotherRequest anotherRequest = new AnotherRequest(someRequest);
SomeResponse someResponse = SomeService.getInstance().someMethod(anotherRequest);
SomeValue someValue = someResponse.getValue();
/**
* Some processes with someValue..
*/
}

The main purpose of this test is testing the process with someValue, so I should just mock the .getValue() method. But the thing is not that easy. Let me put more related classes here:
SomeService.class

1
2
3
4
5
6
7
8
9
10
11
12
13
public final class SomeService {
private static SomeService instance = new SomeService();
static {
// A static block
}
protected SomeService() {}
public static SomeService getInstance() {
return instance;
}
public SomeResponse someMethod(AnotherRequest anotherRequest) {
// Implementation of the method..
}
}

SomeResponse.class

1
2
3
4
5
public class SomeResponse {
public SomeValue getValue() {
// Implementation of getValue()
}
}

SomeValue.class

1
2
3
4
5
6
7
8
9
public class SomeValue {
private String name;
private void populateValue(PreDefinedType preDefinedType) {
// Generate name from a preDefinedType, basically a black box.
}
public String getName() {
return name;
}
}

Read More

This template is used for later markdown reference.

Fonts:

1
2
3
4
5
*Italics*
**Bold**
***Italics and Bold***
~~Scratch~~
It also works if you change the star(*) into underline(_).

Italics, Bold, Italics and Bold, Scratch

1
[My Website](http://kidchen.github.io/)

My Website

Reference:

Add “>“ before a line to express reference (add more “>“ to do nest).

This is a reference.

This is a nested reference.

Quote:

Say something.

[Author AAuthor B] [link] [source_link_title]

For more information, visit this page.

Different subtitles:

Add one to six sharps(#) and a space before the head.

Head1

Head2

Head3

Head4

Head5
Head6

Codes:

Use “`“ around the inline code or use “```“ to define coding area.

This is an inline code.

[title] [url] [link text]
1
code snippet
1
$ hexo new "My New Post"

List:

Use “*“, “+“ or “-“ followed with a space to express unordered list.

  • unordered list
  • nested unordered list
  • nested unordered list
  • nested unordered list
  • nested unordered list

Use numbers followed with a dot and a space to express ordered list.

  1. ordered list
  2. ordered list
  3. ordered list

Insert img:

1
![text](/path/to/your/img.jpg "option-title")

Miscellaneous:

Use three or more “*“, “-“ or “_“ to add divide line.
Note: There is no other characters in the divide line except spaces

Use “\“ as the escape character.

Use <!-- more --> to add “more” button.

A very nice Cheat Sheet for Markdown syntax.

Read More

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×