This repository was archived by the owner on Aug 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +94
-24
lines changed
main/java/com/wego/httpcache/dao/mappers
test/java/com/wego/httpcache/dao/mappers Expand file tree Collapse file tree 4 files changed +94
-24
lines changed Original file line number Diff line number Diff line change 66public class CachedResponseEntityToCachedResponse {
77
88 public CachedResponse transform (CachedResponseEntity cachedResponseEntity ) {
9- return new CachedResponse .Builder ()
10- .setId (cachedResponseEntity .getId ())
11- .setStatusCode (cachedResponseEntity .getStatusCode ())
12- .setStatusText (cachedResponseEntity .getStatusText ())
13- .setHeaders (cachedResponseEntity .getHeaders ())
14- .setCookies (cachedResponseEntity .getCookies ())
15- .setResponseBody (cachedResponseEntity .getResponseBody ())
16- .build ();
9+ CachedResponse cachedResponse = null ;
10+
11+ if (cachedResponseEntity != null ) {
12+ cachedResponse =
13+ new CachedResponse .Builder ()
14+ .setId (cachedResponseEntity .getId ())
15+ .setStatusCode (cachedResponseEntity .getStatusCode ())
16+ .setStatusText (cachedResponseEntity .getStatusText ())
17+ .setHeaders (cachedResponseEntity .getHeaders ())
18+ .setCookies (cachedResponseEntity .getCookies ())
19+ .setResponseBody (cachedResponseEntity .getResponseBody ())
20+ .build ();
21+ }
22+
23+ return cachedResponse ;
1724 }
1825}
Original file line number Diff line number Diff line change 66
77public class CachedResponseToCachedResponseEntity {
88
9- public CachedResponseEntity transform (CachedResponse cachedResponse ) {
9+ public CachedResponseEntity transform (CachedResponse cachedResponse ) throws IOException {
1010 CachedResponseEntity cachedResponseEntity = null ;
11- String responseBody = null ;
1211
13- try {
14- responseBody = cachedResponse .getResponseBody ();
15- } catch (IOException e ) {
16- e .printStackTrace ();
12+ if (cachedResponse != null ) {
13+ cachedResponseEntity =
14+ new CachedResponseEntity .Builder ()
15+ .setId (cachedResponse .getId ())
16+ .setResponseBody (cachedResponse .getResponseBody ())
17+ .setCookies (cachedResponse .getCookies ())
18+ .setHeaders (cachedResponse .getHeaders ())
19+ .setStatusText (cachedResponse .getStatusText ())
20+ .setStatusCode (cachedResponse .getStatusCode ())
21+ .build ();
1722 }
1823
19- cachedResponseEntity =
20- new CachedResponseEntity .Builder ()
21- .setResponseBody (cachedResponse .getId ())
22- .setResponseBody (responseBody )
23- .setCookies (cachedResponse .getCookies ())
24- .setHeaders (cachedResponse .getHeaders ())
25- .setStatusText (cachedResponse .getStatusText ())
26- .setStatusCode (cachedResponse .getStatusCode ())
27- .build ();
28-
2924 return cachedResponseEntity ;
3025 }
3126}
Original file line number Diff line number Diff line change 1+ package com .wego .httpcache .dao .mappers ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import com .wego .httpcache .dao .entities .CachedResponseEntity ;
6+ import com .wego .httpcache .dao .models .CachedResponse ;
7+ import com .wego .httpcache .fixtures .CachedResponseEntityFixture ;
8+ import org .junit .Test ;
9+
10+ public class TestCachedResponseEntityToCachedResponse {
11+ private CachedResponseEntityToCachedResponse cachedResponseEntityToCachedResponse =
12+ new CachedResponseEntityToCachedResponse ();
13+
14+ @ Test
15+ public void transform_whenInputParamIsNull_returnsNull () throws Exception {
16+ assertThat (cachedResponseEntityToCachedResponse .transform (null )).isNull ();
17+ }
18+
19+ @ Test
20+ public void transform_whenValidInputParam_returnsCachedResponse () throws Exception {
21+ CachedResponseEntity cachedResponseEntity = CachedResponseEntityFixture .create ();
22+
23+ CachedResponse cachedResponse =
24+ cachedResponseEntityToCachedResponse .transform (cachedResponseEntity );
25+
26+ assertThat (cachedResponse .getId ()).isEqualTo (cachedResponseEntity .getId ());
27+ assertThat (cachedResponse .getCookies ()).isEqualTo (cachedResponseEntity .getCookies ());
28+ assertThat (cachedResponse .getHeaders ().toString ())
29+ .contains (cachedResponseEntity .getHeaders ().toString ());
30+ assertThat (cachedResponse .getResponseBody ()).isEqualTo (cachedResponseEntity .getResponseBody ());
31+ assertThat (cachedResponse .getStatusCode ()).isEqualTo (cachedResponseEntity .getStatusCode ());
32+ assertThat (cachedResponse .getStatusText ()).isEqualTo (cachedResponseEntity .getStatusText ());
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package com .wego .httpcache .dao .mappers ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import com .wego .httpcache .dao .entities .CachedResponseEntity ;
6+ import com .wego .httpcache .dao .models .CachedResponse ;
7+ import com .wego .httpcache .fixtures .CachedResponseFixture ;
8+ import org .junit .Test ;
9+
10+ public class TestCachedResponseToCachedResponseEntity {
11+ private CachedResponseToCachedResponseEntity cachedResponseToCachedResponseEntity =
12+ new CachedResponseToCachedResponseEntity ();
13+
14+ @ Test
15+ public void transform_whenInputParamIsNull_returnsNull () throws Exception {
16+ assertThat (cachedResponseToCachedResponseEntity .transform (null )).isNull ();
17+ }
18+
19+ @ Test
20+ public void transform_whenValidInputParam_returnsCachedResponseEntity () throws Exception {
21+ CachedResponse cachedResponse = CachedResponseFixture .create ();
22+
23+ CachedResponseEntity cachedResponseEntity =
24+ cachedResponseToCachedResponseEntity .transform (cachedResponse );
25+
26+ assertThat (cachedResponseEntity .getId ()).isEqualTo (cachedResponse .getId ());
27+ assertThat (cachedResponseEntity .getCookies ()).isEqualTo (cachedResponse .getCookies ());
28+ assertThat (cachedResponseEntity .getHeaders ().toString ())
29+ .contains (cachedResponse .getHeaders ().toString ());
30+ assertThat (cachedResponseEntity .getResponseBody ()).isEqualTo (cachedResponse .getResponseBody ());
31+ assertThat (cachedResponseEntity .getStatusCode ()).isEqualTo (cachedResponse .getStatusCode ());
32+ assertThat (cachedResponseEntity .getStatusText ()).isEqualTo (cachedResponse .getStatusText ());
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments