1+ package org .springdoc .core .model ;
2+
3+ import org .junit .jupiter .api .Test ;
4+ import org .springdoc .core .models .MethodAttributes ;
5+
6+ import java .lang .reflect .Method ;
7+ import java .util .Locale ;
8+
9+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
10+
11+ public class MethodAttributesTest {
12+
13+ @ Test
14+ public void testMergeArrays () throws Exception {
15+ MethodAttributes methodAttributes = new MethodAttributes ("application/json" , "application/xml" , Locale .ENGLISH );
16+
17+ String [] array1 = {"application/json" , "application/xml" };
18+ String [] array2 = {"application/xml" , "application/yaml" };
19+
20+ String [] expected = {"application/json" , "application/xml" , "application/yaml" };
21+
22+ Method mergeArraysMethod = MethodAttributes .class .getDeclaredMethod ("mergeArrays" , String [].class , String [].class );
23+ mergeArraysMethod .setAccessible (true );
24+ String [] result = (String []) mergeArraysMethod .invoke (methodAttributes , (Object ) array1 , (Object ) array2 );
25+
26+ assertArrayEquals (expected , result );
27+ }
28+
29+ @ Test
30+ public void testMergeArraysWithNullArray1 () throws Exception {
31+ MethodAttributes methodAttributes = new MethodAttributes ("application/json" , "application/xml" , Locale .ENGLISH );
32+
33+ String [] array1 = null ;
34+ String [] array2 = {"application/xml" , "application/yaml" };
35+
36+ String [] expected = {"application/xml" , "application/yaml" };
37+
38+ Method mergeArraysMethod = MethodAttributes .class .getDeclaredMethod ("mergeArrays" , String [].class , String [].class );
39+ mergeArraysMethod .setAccessible (true );
40+ String [] result = (String []) mergeArraysMethod .invoke (methodAttributes , (Object ) array1 , (Object ) array2 );
41+
42+ assertArrayEquals (expected , result );
43+ }
44+
45+ @ Test
46+ public void testDefaultProducesMediaType () {
47+ MethodAttributes methodAttributes = new MethodAttributes ("application/json" , "application/xml" , Locale .ENGLISH );
48+
49+ Method method = this .getClass ().getDeclaredMethods ()[0 ];
50+ methodAttributes .calculateConsumesProduces (method );
51+
52+ String [] expectedProduces = {"application/xml" };
53+ String [] resultProduces = methodAttributes .getMethodProduces ();
54+
55+ assertArrayEquals (expectedProduces , resultProduces );
56+ }
57+
58+ @ Test
59+ public void testDefaultConsumesMediaType () {
60+ MethodAttributes methodAttributes = new MethodAttributes ("application/json" , "application/xml" , Locale .ENGLISH );
61+
62+ Method method = this .getClass ().getDeclaredMethods ()[0 ];
63+ methodAttributes .calculateConsumesProduces (method );
64+
65+ String [] expectedConsumes = {"application/json" };
66+ String [] resultConsumes = methodAttributes .getMethodConsumes ();
67+
68+ assertArrayEquals (expectedConsumes , resultConsumes );
69+ }
70+ }
0 commit comments