001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.common.text;
017
018import static org.hamcrest.core.IsNull.nullValue;
019import static org.hamcrest.core.Is.is;
020import static org.hamcrest.core.IsNull.notNullValue;
021import static org.junit.Assert.assertEquals;
022import static org.junit.Assert.assertThat;
023import org.junit.Before;
024import org.junit.Test;
025
026/**
027 * @author Randall Hauch
028 */
029public class NoOpEncoderTest {
030
031    private NoOpEncoder encoder = new NoOpEncoder();
032
033    @Before
034    public void beforeEach() {
035    }
036
037    protected void checkForNoEncoding( String input ) {
038        String output = this.encoder.encode(input);
039        assertThat(output, is(notNullValue()));
040        assertEquals(input, output);
041
042        String decoded = this.encoder.decode(output);
043        assertEquals(output, decoded);
044        assertEquals(input, decoded);
045    }
046
047    @Test
048    public void shouldReturnNullIfPassedNull() {
049        assertThat(this.encoder.encode(null), is(nullValue()));
050        assertThat(this.encoder.decode(null), is(nullValue()));
051    }
052
053    @Test
054    public void shouldNeverEncodeAnyString() {
055        checkForNoEncoding("%");
056        checkForNoEncoding("abcdefghijklmnopqrstuvwxyz");
057        checkForNoEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
058        checkForNoEncoding("0123456789");
059        checkForNoEncoding("-_.!~*\'()");
060        checkForNoEncoding("http://acme.com/this is %something?get=true;something=false");
061    }
062}