Skip to content

Commit

Permalink
gununu...
Browse files Browse the repository at this point in the history
  • Loading branch information
backpaper0 committed Jun 23, 2024
1 parent 9b665dd commit 4aeb782
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 4aeb782

Please sign in to comment.