|
| 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() { |
| 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 | + String[] result = methodAttributes.mergeArrays(array1, array2); |
| 22 | + |
| 23 | + assertArrayEquals(expected, result); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + public void testMergeArraysWithNullArray1() { |
| 28 | + MethodAttributes methodAttributes = new MethodAttributes("application/json", "application/xml", Locale.ENGLISH); |
| 29 | + |
| 30 | + String[] array1 = null; |
| 31 | + String[] array2 = {"application/xml", "application/yaml"}; |
| 32 | + |
| 33 | + String[] expected = {"application/xml", "application/yaml"}; |
| 34 | + String[] result = methodAttributes.mergeArrays(array1, array2); |
| 35 | + |
| 36 | + assertArrayEquals(expected, result); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testDefaultProducesMediaType() { |
| 41 | + MethodAttributes methodAttributes = new MethodAttributes("application/json", "application/xml", Locale.ENGLISH); |
| 42 | + |
| 43 | + Method method = this.getClass().getDeclaredMethods()[0]; |
| 44 | + methodAttributes.calculateConsumesProduces(method); |
| 45 | + |
| 46 | + String[] expectedProduces = {"application/xml"}; |
| 47 | + String[] resultProduces = methodAttributes.getMethodProduces(); |
| 48 | + |
| 49 | + assertArrayEquals(expectedProduces, resultProduces); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testDefaultConsumesMediaType() { |
| 54 | + MethodAttributes methodAttributes = new MethodAttributes("application/json", "application/xml", Locale.ENGLISH); |
| 55 | + |
| 56 | + Method method = this.getClass().getDeclaredMethods()[0]; |
| 57 | + methodAttributes.calculateConsumesProduces(method); |
| 58 | + |
| 59 | + String[] expectedConsumes = {"application/json"}; |
| 60 | + String[] resultConsumes = methodAttributes.getMethodConsumes(); |
| 61 | + |
| 62 | + assertArrayEquals(expectedConsumes, resultConsumes); |
| 63 | + } |
| 64 | +} |
0 commit comments