package org.influxdb.dto;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;


/**
 * Test for the Query DTO.
 *
 * @author jord [at] moz.com
 *
 */
public class QueryTest {

	/**
	 * Test that equals does what it is supposed to do.
	 */
	@Test
	public void testEqualsAndHashCode() {
		String stringA0 = "thesame";
		String stringA1 = "thesame";
		String stringB0 = "notthesame";

		Query queryA0 = new Query(stringA0, stringA0);
		Query queryA1 = new Query(stringA1, stringA1);
		Query queryB0 = new Query(stringA0, stringB0);
		Query queryC0 = new Query(stringB0, stringA0);

		assertThat(queryA0).isEqualTo(queryA1);
		assertThat(queryA0).isNotEqualTo(queryB0);
		assertThat(queryB0).isNotEqualTo(queryC0);

		assertThat(queryA0.hashCode()).isEqualTo(queryA1.hashCode());
		assertThat(queryA0.hashCode()).isNotEqualTo(queryB0.hashCode());
	}
}

@@ -90,21 +90,211 @@
 ort 
-org.junit.Tes
+com.google.common.base.Charsets;%0Aimport com.google.common.primitives.Chars;%0Aimport org.junit.Test;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLDecoder;%0Aimport java.nio.charset.Charse
 t;%0A%0A
@@ -990,16 +990,16 @@
 ode());%0A
-
 %09%09assert
@@ -1059,11 +1059,1989 @@
 e());%0A%09%7D
+%0A%0A%09/**%0A%09 * Test encode does what it is supposed to do.%0A%09 */%0A%09@Test%0A%09public void testEncode() throws UnsupportedEncodingException %7B%0A%09%09String queryString1 = %22SELECT * FROM cpu%22;%0A%09%09String queryString2 = %22SELECT * FROM cpu;SELECT * FROM cpu%22;%0A%0A%09%09String encodedQueryString1 = Query.encode(queryString1);%0A%09%09String encodedQueryString2 = Query.encode(queryString2);%0A%0A%09%09assertThat(decode(encodedQueryString1)).isEqualTo(queryString1);%0A%09%09assertThat(decode(encodedQueryString2)).isEqualTo(queryString2);%0A%09%09assertThat(encodedQueryString2).doesNotContain(%22;%22);%0A%09%7D%0A%0A%09/**%0A%09 * Test getCommandWithUrlEncoded does what it is supposed to do.%0A%09 */%0A%09@Test%0A%09public void testGetCommandWithUrlEncoded() throws UnsupportedEncodingException %7B%0A%09%09String queryString1 = %22CREATE DATABASE %5C%22testdb%5C%22%22;%0A%09%09String queryString2 = %22SELECT * FROM cpu;SELECT * FROM cpu;%22;%0A%09%09String queryString3 = %22%253B%252B%25%22;%0A%09%09String queryString4 = %22non_escape%22;%0A%09%09String database = %22testdb%22;%0A%0A%09%09Query query1 = new Query(queryString1, database);%0A%09%09Query query2 = new Query(queryString2, database);%0A%09%09Query query3 = new Query(queryString3, database);%0A%09%09Query query4 = new Query(queryString4, database);%0A%0A%09%09assertThat(query1.getCommandWithUrlEncoded()).isNotEqualTo(query1.getCommand());%0A%09%09assertThat(decode(query1.getCommandWithUrlEncoded())).isEqualTo(query1.getCommand());%0A%0A%09%09assertThat(query2.getCommandWithUrlEncoded()).isNotEqualTo(query2.getCommand());%0A%09%09assertThat(decode(query2.getCommandWithUrlEncoded())).isEqualTo(query2.getCommand());%0A%0A%09%09assertThat(query3.getCommandWithUrlEncoded()).isNotEqualTo(query3.getCommand());%0A%09%09assertThat(decode(query3.getCommandWithUrlEncoded())).isEqualTo(query3.getCommand());%0A%0A%09%09assertThat(query4.getCommandWithUrlEncoded()).isEqualTo(query4.getCommand());%0A%09%09assertThat(decode(query4.getCommandWithUrlEncoded())).isEqualTo(query4.getCommand());%0A%09%7D%0A%0A%09private static String decode(String str) throws UnsupportedEncodingException %7B%0A%09%09return URLDecoder.decode(str, Charsets.UTF_8.toString());%0A%09%7D
 %0A%7D%0A

add unit test