001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.commons.domain; 019 020import static org.fcrepo.kernel.api.RdfLexicon.LDP_NAMESPACE; 021import static org.junit.Assert.assertEquals; 022import static org.junit.Assert.assertFalse; 023import static org.junit.Assert.assertNotNull; 024import static org.junit.Assert.assertTrue; 025 026import java.text.ParseException; 027 028import org.junit.Test; 029 030/** 031 * @author cabeer 032 */ 033public class PreferTagTest { 034 035 @Test 036 public void testEmpty() { 037 final PreferTag preferTag = PreferTag.emptyTag(); 038 assertEquals("", preferTag.getTag()); 039 assertEquals("", preferTag.getValue()); 040 assertTrue(preferTag.getParams().isEmpty()); 041 } 042 043 @Test 044 public void testTrailingSemicolon() throws ParseException { 045 final PreferTag preferTag = new PreferTag("foo=bar;"); 046 assertNotNull(preferTag.getParams()); 047 } 048 049 @Test 050 public void testEquals() throws ParseException { 051 final PreferTag preferTag1 = new PreferTag("handling=lenient; received=\"minimal\""); 052 final PreferTag preferTag2 = new PreferTag("handling=lenient; received=\"minimal\""); 053 final PreferTag preferTag3 = PreferTag.emptyTag(); 054 assertTrue(preferTag1.equals(preferTag2)); 055 assertTrue(preferTag1.equals(preferTag1)); // ensure consistency 056 assertTrue(preferTag2.equals(preferTag1)); 057 assertFalse(preferTag1.equals(preferTag3)); 058 assertFalse(preferTag1.equals(null)); 059 assertFalse(preferTag1.equals("some string")); 060 } 061 062 @Test 063 public void testHashCode() throws ParseException { 064 doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""), 065 new PreferTag("handling=lenient; received=\"minimal\""), 066 true); 067 068 doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""), 069 new PreferTag("return=representation; include=\"" + LDP_NAMESPACE + "PreferMinimalContainer\""), 070 false); 071 072 doTestHashCode(new PreferTag("handling=lenient; received=\"minimal\""), 073 PreferTag.emptyTag(), 074 false); 075 } 076 077 private static void doTestHashCode(final PreferTag tag0, final PreferTag tag1, final boolean expectEqual) { 078 assertEquals(expectEqual, tag0.equals(tag1)); 079 assertEquals(expectEqual, tag0.hashCode() == tag1.hashCode()); 080 } 081 082}