Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 3b57c12

Browse files
author
Adam Lindenthal
committed
JERSEY-2847 AcceptableMediaTypes overrides toString() incorrectly
Change-Id: I7f614c4aa757e9e9758fde5b7c68559e72d4137e
1 parent 0239f91 commit 3b57c12

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed

core-common/src/main/java/org/glassfish/jersey/message/internal/AcceptableMediaType.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,4 @@ public int hashCode() {
200200
int hash = super.hashCode();
201201
return (this.q == Quality.DEFAULT) ? hash : 47 * hash + this.q;
202202
}
203-
204-
@Override
205-
public String toString() {
206-
return "{" + super.toString() + ", q=" + q + "}";
207-
}
208203
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.message.internal;
41+
42+
import java.util.Arrays;
43+
import java.util.HashMap;
44+
import java.util.List;
45+
import java.util.Map;
46+
47+
import org.junit.Assert;
48+
import org.junit.Test;
49+
import org.junit.runner.RunWith;
50+
import org.junit.runners.Parameterized;
51+
52+
53+
/**
54+
* Acceptable media type unit tests.
55+
*
56+
* @author Adam Lindenthal (adam.lindenthal at oracle.com)
57+
*/
58+
@RunWith(Parameterized.class)
59+
public class AcceptableMediaTypeStringRepresentationTest {
60+
@Parameterized.Parameters
61+
// expected result, acceptable media type
62+
public static List<Object[]> getParameters() {
63+
final Map<String, String> emptyParams = new HashMap<String, String>();
64+
final Map<String, String> params = new HashMap<String, String>();
65+
params.put("myParam", "myValue");
66+
67+
return Arrays.asList(new Object[][]{
68+
{"*/*", new AcceptableMediaType("*", "*")},
69+
{"*/*", new AcceptableMediaType("*", "*", Quality.DEFAULT, emptyParams)},
70+
{"*/*;q=0.75", new AcceptableMediaType("*", "*", 750, emptyParams)},
71+
{"text/html", new AcceptableMediaType("text", "html", Quality.DEFAULT, null)},
72+
{"text/html;q=0.5", new AcceptableMediaType("text", "html", 500, emptyParams)},
73+
{"image/*;myparam=myValue;q=0.8", new AcceptableMediaType("image", "*", 800, params)},
74+
});
75+
}
76+
77+
private final String expectedValue;
78+
private final AcceptableMediaType testedType;
79+
80+
public AcceptableMediaTypeStringRepresentationTest(final String expectedValue,
81+
final AcceptableMediaType testedType) {
82+
this.expectedValue = expectedValue;
83+
this.testedType = testedType;
84+
}
85+
86+
@Test
87+
public void testStringRepresentation() {
88+
final MediaTypeProvider provider = new MediaTypeProvider();
89+
Assert.assertEquals(expectedValue, testedType.toString());
90+
provider.fromString(testedType.toString());
91+
}
92+
}

0 commit comments

Comments
 (0)