From 4aeb782ac80ac3c06b6806d5a2dc760d6daca685 Mon Sep 17 00:00:00 2001 From: Uragami Taichi Date: Sun, 23 Jun 2024 17:32:36 +0900 Subject: [PATCH] gununu... --- .../accesslog/ElapsedTimeConverterTest.java | 82 +++++++++---------- .../accesslog/KeepingNameConverterTest.java | 74 ++++++++--------- .../accesslog/SessionIdConverterTest.java | 74 ++++++++--------- .../accesslog/UserNameConverterTest.java | 74 ++++++++--------- 4 files changed, 152 insertions(+), 152 deletions(-) diff --git a/custom-logging/src/test/java/com/example/common/accesslog/ElapsedTimeConverterTest.java b/custom-logging/src/test/java/com/example/common/accesslog/ElapsedTimeConverterTest.java index f1cff2d5..b724a14c 100644 --- a/custom-logging/src/test/java/com/example/common/accesslog/ElapsedTimeConverterTest.java +++ b/custom-logging/src/test/java/com/example/common/accesslog/ElapsedTimeConverterTest.java @@ -7,61 +7,61 @@ import org.junit.jupiter.api.Test; -import ch.qos.logback.access.spi.IAccessEvent; +import ch.qos.logback.access.common.spi.IAccessEvent; import jakarta.servlet.http.HttpServletRequest; public class ElapsedTimeConverterTest { - ElapsedTimeConverter sut = new ElapsedTimeConverter(); + ElapsedTimeConverter sut = new ElapsedTimeConverter(); - @Test - void リクエスト処理に要した時間から外部APIの呼び出しにかかった時間を差し引く() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(3L)); - when(request.getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn(TimeUnit.SECONDS.toNanos(2L)); + @Test + void リクエスト処理に要した時間から外部APIの呼び出しにかかった時間を差し引く() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(3L)); + when(request.getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn(TimeUnit.SECONDS.toNanos(2L)); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("1000", actual); + assertEquals("1000", actual); - verify(event).getRequest(); - verify(event).getElapsedTime(); - verify(request).getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(event).getElapsedTime(); + verify(request).getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void 外部APIの呼び出しを行っていない場合はそのまま() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(1L)); + @Test + void 外部APIの呼び出しを行っていない場合はそのまま() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(1L)); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("1000", actual); + assertEquals("1000", actual); - verify(event).getRequest(); - verify(event).getElapsedTime(); - verify(request).getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(event).getElapsedTime(); + verify(request).getAttribute(ElapsedTimeConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストを取得できない場合もそのまま() { - IAccessEvent event = mock(IAccessEvent.class); - when(event.getRequest()).thenReturn(null); - when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(1L)); + @Test + void リクエストを取得できない場合もそのまま() { + IAccessEvent event = mock(IAccessEvent.class); + when(event.getRequest()).thenReturn(null); + when(event.getElapsedTime()).thenReturn(TimeUnit.SECONDS.toMillis(1L)); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("1000", actual); + assertEquals("1000", actual); - verify(event).getRequest(); - verify(event).getElapsedTime(); - verifyNoMoreInteractions(event); - } + verify(event).getRequest(); + verify(event).getElapsedTime(); + verifyNoMoreInteractions(event); + } } diff --git a/custom-logging/src/test/java/com/example/common/accesslog/KeepingNameConverterTest.java b/custom-logging/src/test/java/com/example/common/accesslog/KeepingNameConverterTest.java index db7c4057..03537377 100644 --- a/custom-logging/src/test/java/com/example/common/accesslog/KeepingNameConverterTest.java +++ b/custom-logging/src/test/java/com/example/common/accesslog/KeepingNameConverterTest.java @@ -5,57 +5,57 @@ import org.junit.jupiter.api.Test; -import ch.qos.logback.access.spi.IAccessEvent; +import ch.qos.logback.access.common.spi.IAccessEvent; import jakarta.servlet.http.HttpServletRequest; public class KeepingNameConverterTest { - KeepingNameConverter sut = new KeepingNameConverter(); + KeepingNameConverter sut = new KeepingNameConverter(); - @Test - void リクエストから名前を取り出して返す() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn("testname"); + @Test + void リクエストから名前を取り出して返す() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn("testname"); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("testname", actual); + assertEquals("testname", actual); - verify(event).getRequest(); - verify(request).getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストに名前が入っていない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn(null); + @Test + void リクエストに名前が入っていない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verify(request).getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(KeepingNameConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストを取得できない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - when(event.getRequest()).thenReturn(null); + @Test + void リクエストを取得できない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + when(event.getRequest()).thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verifyNoMoreInteractions(event); - } + verify(event).getRequest(); + verifyNoMoreInteractions(event); + } } diff --git a/custom-logging/src/test/java/com/example/common/accesslog/SessionIdConverterTest.java b/custom-logging/src/test/java/com/example/common/accesslog/SessionIdConverterTest.java index 276aa095..ef34b99a 100644 --- a/custom-logging/src/test/java/com/example/common/accesslog/SessionIdConverterTest.java +++ b/custom-logging/src/test/java/com/example/common/accesslog/SessionIdConverterTest.java @@ -5,57 +5,57 @@ import org.junit.jupiter.api.Test; -import ch.qos.logback.access.spi.IAccessEvent; +import ch.qos.logback.access.common.spi.IAccessEvent; import jakarta.servlet.http.HttpServletRequest; public class SessionIdConverterTest { - SessionIdConverter sut = new SessionIdConverter(); + SessionIdConverter sut = new SessionIdConverter(); - @Test - void リクエストからセッションIDを取り出して返す() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn("00000000-0000-0000-0000-000000000000"); + @Test + void リクエストからセッションIDを取り出して返す() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn("00000000-0000-0000-0000-000000000000"); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("00000000-0000-0000-0000-000000000000", actual); + assertEquals("00000000-0000-0000-0000-000000000000", actual); - verify(event).getRequest(); - verify(request).getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストにセッションIDが入っていない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn(null); + @Test + void リクエストにセッションIDが入っていない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verify(request).getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(SessionIdConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストを取得できない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - when(event.getRequest()).thenReturn(null); + @Test + void リクエストを取得できない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + when(event.getRequest()).thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verifyNoMoreInteractions(event); - } + verify(event).getRequest(); + verifyNoMoreInteractions(event); + } } diff --git a/custom-logging/src/test/java/com/example/common/accesslog/UserNameConverterTest.java b/custom-logging/src/test/java/com/example/common/accesslog/UserNameConverterTest.java index d63d8b7a..5d66c563 100644 --- a/custom-logging/src/test/java/com/example/common/accesslog/UserNameConverterTest.java +++ b/custom-logging/src/test/java/com/example/common/accesslog/UserNameConverterTest.java @@ -5,57 +5,57 @@ import org.junit.jupiter.api.Test; -import ch.qos.logback.access.spi.IAccessEvent; +import ch.qos.logback.access.common.spi.IAccessEvent; import jakarta.servlet.http.HttpServletRequest; public class UserNameConverterTest { - UserNameConverter sut = new UserNameConverter(); + UserNameConverter sut = new UserNameConverter(); - @Test - void リクエストからユーザー名を取り出して返す() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn("testuser"); + @Test + void リクエストからユーザー名を取り出して返す() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn("testuser"); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals("testuser", actual); + assertEquals("testuser", actual); - verify(event).getRequest(); - verify(request).getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストにユーザー名が入っていない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - HttpServletRequest request = mock(HttpServletRequest.class); - when(event.getRequest()).thenReturn(request); - when(request.getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME)) - .thenReturn(null); + @Test + void リクエストにユーザー名が入っていない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + HttpServletRequest request = mock(HttpServletRequest.class); + when(event.getRequest()).thenReturn(request); + when(request.getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME)) + .thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verify(request).getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME); - verifyNoMoreInteractions(event, request); - } + verify(event).getRequest(); + verify(request).getAttribute(UserNameConverter.REQUEST_ATTRIBUTE_NAME); + verifyNoMoreInteractions(event, request); + } - @Test - void リクエストを取得できない場合はNA() { - IAccessEvent event = mock(IAccessEvent.class); - when(event.getRequest()).thenReturn(null); + @Test + void リクエストを取得できない場合はNA() { + IAccessEvent event = mock(IAccessEvent.class); + when(event.getRequest()).thenReturn(null); - String actual = sut.convert(event); + String actual = sut.convert(event); - assertEquals(IAccessEvent.NA, actual); + assertEquals(IAccessEvent.NA, actual); - verify(event).getRequest(); - verifyNoMoreInteractions(event); - } + verify(event).getRequest(); + verifyNoMoreInteractions(event); + } }