Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-6' into v6-master
Browse files Browse the repository at this point in the history
  • Loading branch information
tisuchida committed Dec 22, 2023
2 parents 6c8a7ba + dee1b3d commit 79d51d0
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 178 deletions.
18 changes: 8 additions & 10 deletions nablarch-jackson-adaptor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.nablarch.integration</groupId>
<artifactId>nablarch-jackson-adaptor</artifactId>
<version>1.0.8</version>
<version>2.0.0</version>

<parent>
<groupId>com.nablarch.integration</groupId>
<artifactId>nablarch-jaxrs-adaptor</artifactId>
<version>1.0.9</version>
<version>2.0.0</version>
</parent>

<dependencies>
Expand All @@ -26,9 +26,8 @@
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<scope>provided</scope>
</dependency>

Expand All @@ -39,9 +38,8 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -50,8 +48,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import nablarch.fw.web.HttpResponse;
import nablarch.fw.web.servlet.ServletExecutionContext;

import javax.servlet.ServletRequest;
import jakarta.servlet.ServletRequest;
import java.io.IOException;
import java.io.Reader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import mockit.Mocked;
import mockit.Expectations;
import nablarch.test.support.reflection.ReflectionUtil;
import org.junit.Test;
import org.mockito.Mockito;

import static org.mockito.Mockito.when;

/**
* {@link Jackson2BodyConverter}のテストクラス。
*/
public class Jackson2BodyConverterTest extends JacksonBodyConverterTestSupport<Jackson2BodyConverter> {

@Override
protected Jackson2BodyConverter createSut() {
return new Jackson2BodyConverter();
Expand Down Expand Up @@ -45,17 +46,18 @@ protected Class<?> getUnrecognizedPropertyExceptionClass() {
}

@Test
public void testWrite_json_failed(@Mocked final ObjectMapper mapper) throws Exception {
public void testWrite_json_failed() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("failed to write response.");

final TestBean bean = new TestBean("aaa",123L, true);
new Expectations() {{
jaxRsContext.getProducesMediaType();
result = "application/json;charset=utf-8";
mapper.writeValueAsString(bean);
result = new JsonMappingException("error");
}};
when(jaxRsContext.getProducesMediaType()).thenReturn("application/json;charset=utf-8");

// mockConstruction だとなぜか ObjectMapper のコンストラクタをモック化できなかったので、
// リフレクションで強制的にモックオブジェクトを設定している
final ObjectMapper objectMapper = Mockito.mock(ObjectMapper.class);
when(objectMapper.writeValueAsString(bean)).thenThrow(new JsonMappingException("error"));
ReflectionUtil.setFieldValue(sut, "objectMapper", objectMapper);

sut.write(bean, executionContext);
}
Expand Down
Loading

0 comments on commit 79d51d0

Please sign in to comment.