static method를 테스트하기위해서 MockedStatic을 사용가능하다. static method를 바로 테스트하면 아래와 같은 오류가 발생한다. org.mockito.exceptions.misusing.MissingMethodInvocationException: 그래서 Mockito의 MockedStatic을 사용한다. try (final MockedStatic mockNumbers = mockStatic(Numbers.class)) { mockNumbers .when(() -> Numbers.getNumbers(anyInt(), anyInt())) .thenReturn(1, 2, 3); }
Object의 toString을 오버라이딩 했는데, 필드값 중 null이 있으면 exception이 발생하는 경우가 있다. 이러한 경우 String.valueOf()를 써주면 된다. public static void main(String args[]) { String str = null; System.out.println(String.valueOf(str)); // This will print a String equal to "null" System.out.println(str.toString()); // This will throw a NullPointerException } String.valueOf 소스코드를 보면 null 처리가 되어있다. public static String valueOf(Obj..
나는 테스트는 주로 이 사이트에서 한다. https://regexr.com/ RegExr: Learn, Build, & Test RegEx RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp). regexr.com 표현식 의미 ^x 문자열의 시작을 표현하며 x 문자로 시작됨을 의미한다. x$ 문자열의 종료를 표현하며 x 문자로 종료됨을 의미한다. .x 임의의 한 문자의 자리수를 표현하며 문자열이 x 로 끝난다는 것을 의미한다. x+ 반복을 표현하며 x 문자가 한번 이상 반복됨을 의미한다. x? 존재여부를 표현하며 x 문자가 존재할 수도, 존재하지 않을 수도 있음을 의미한다. x* 반복여부를 표현하며 x 문..
- Total
- Today
- Yesterday