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

Commit b7af52c

Browse files
committed
JERSEY-3069: LanguageTag#equals(...) fix.
Change-Id: I040a43117a1979db8beb5d5d8498fa6e93390525
1 parent 4bc0247 commit b7af52c

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -89,10 +89,7 @@ public boolean equals(Object obj) {
8989
return false;
9090
}
9191
final AcceptableLanguageTag other = (AcceptableLanguageTag) obj;
92-
if (this.quality != other.quality) {
93-
return false;
94-
}
95-
return true;
92+
return this.quality == other.quality;
9693
}
9794

9895
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -178,7 +178,7 @@ public boolean equals(final Object o) {
178178
if (this == o) {
179179
return true;
180180
}
181-
if (!(o instanceof LanguageTag) || o.getClass() == this.getClass()) {
181+
if (!(o instanceof LanguageTag) || o.getClass() != this.getClass()) {
182182
return false;
183183
}
184184

core-common/src/test/java/org/glassfish/jersey/message/internal/LanguageTagTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -45,6 +45,8 @@
4545
import org.junit.Test;
4646
import static org.hamcrest.MatcherAssert.assertThat;
4747
import static org.hamcrest.Matchers.equalToIgnoringCase;
48+
import static org.junit.Assert.assertFalse;
49+
import static org.junit.Assert.assertTrue;
4850

4951
/**
5052
* Tests for {@link LanguageTag} class.
@@ -70,6 +72,22 @@ public void testLanguageRegion() throws Exception {
7072
_test("es", "419");
7173
}
7274

75+
@Test
76+
public void testEquals() {
77+
LanguageTag lt1 = new LanguageTag("en", "us");
78+
LanguageTag lt2 = new LanguageTag("en", "us");
79+
80+
assertTrue(lt1.equals(lt2));
81+
}
82+
83+
@Test
84+
public void testNonEquals() {
85+
LanguageTag lt1 = new LanguageTag("en", "us");
86+
LanguageTag lt2 = new LanguageTag("en", "gb");
87+
88+
assertFalse(lt1.equals(lt2));
89+
}
90+
7391
private void _test(final String primary, final String sub) throws Exception {
7492
final LanguageTag tag = LanguageTag.valueOf(primary + "-" + sub);
7593

0 commit comments

Comments
 (0)