Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToList.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToList.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToList.java Mon Aug 10 16:15:37 2015 @@ -1,34 +1,34 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion; - -import java.util.LinkedList; -import java.util.List; - -public class GenericSingletonToList<T> extends AbstractConverter<T, List<T>> { - public GenericSingletonToList(Class<T> sourceClass) { - super(sourceClass, List.class); - } - - public List<T> convert(T obj) throws ConversionException { - List<T> tempList = new LinkedList<T>(); - tempList.add(obj); - return tempList; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion; + +import java.util.LinkedList; +import java.util.List; + +public class GenericSingletonToList<T> extends AbstractConverter<T, List<T>> { + public GenericSingletonToList(Class<T> sourceClass) { + super(sourceClass, List.class); + } + + public List<T> convert(T obj) throws ConversionException { + List<T> tempList = new LinkedList<T>(); + tempList.add(obj); + return tempList; + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToList.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToSet.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToSet.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToSet.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToSet.java Mon Aug 10 16:15:37 2015 @@ -1,34 +1,34 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion; - -import java.util.HashSet; -import java.util.Set; - -public class GenericSingletonToSet<T> extends AbstractConverter<T, Set<T>> { - public GenericSingletonToSet(Class<T> sourceClass) { - super(sourceClass, Set.class); - } - - public Set<T> convert(T obj) throws ConversionException { - Set<T> tempSet = new HashSet<T>(); - tempSet.add(obj); - return tempSet; - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion; + +import java.util.HashSet; +import java.util.Set; + +public class GenericSingletonToSet<T> extends AbstractConverter<T, Set<T>> { + public GenericSingletonToSet(Class<T> sourceClass) { + super(sourceClass, Set.class); + } + + public Set<T> convert(T obj) throws ConversionException { + Set<T> tempSet = new HashSet<T>(); + tempSet.add(obj); + return tempSet; + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/GenericSingletonToSet.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java Mon Aug 10 16:15:37 2015 @@ -1,90 +1,90 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.lang.JSON; -import org.ofbiz.base.util.UtilGenerics; - -/** JSON Converter classes. */ -public class JSONConverters implements ConverterLoader { - - public static class JSONToList extends AbstractConverter<JSON, List<Object>> { - public JSONToList() { - super(JSON.class, List.class); - } - - public List<Object> convert(JSON obj) throws ConversionException { - try { - return UtilGenerics.<List<Object>>cast(obj.toObject(List.class)); - } catch (IOException e) { - throw new ConversionException(e); - } - } - } - - public static class JSONToMap extends AbstractConverter<JSON, Map<String, Object>> { - public JSONToMap() { - super(JSON.class, Map.class); - } - - public Map<String, Object> convert(JSON obj) throws ConversionException { - try { - return UtilGenerics.<Map<String, Object>>cast(obj.toObject(Map.class)); - } catch (IOException e) { - throw new ConversionException(e); - } - } - } - - public static class ListToJSON extends AbstractConverter<List<Object>, JSON> { - public ListToJSON() { - super(List.class, JSON.class); - } - - public JSON convert(List<Object> obj) throws ConversionException { - try { - return JSON.from(obj); - } catch (IOException e) { - throw new ConversionException(e); - } - } - } - - public static class MapToJSON extends AbstractConverter<Map<String, Object>, JSON> { - public MapToJSON() { - super(Map.class, JSON.class); - } - - public JSON convert(Map<String, Object> obj) throws ConversionException { - try { - return JSON.from(obj); - } catch (IOException e) { - throw new ConversionException(e); - } - } - } - - public void loadConverters() { - Converters.loadContainedConverters(JSONConverters.class); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.lang.JSON; +import org.ofbiz.base.util.UtilGenerics; + +/** JSON Converter classes. */ +public class JSONConverters implements ConverterLoader { + + public static class JSONToList extends AbstractConverter<JSON, List<Object>> { + public JSONToList() { + super(JSON.class, List.class); + } + + public List<Object> convert(JSON obj) throws ConversionException { + try { + return UtilGenerics.<List<Object>>cast(obj.toObject(List.class)); + } catch (IOException e) { + throw new ConversionException(e); + } + } + } + + public static class JSONToMap extends AbstractConverter<JSON, Map<String, Object>> { + public JSONToMap() { + super(JSON.class, Map.class); + } + + public Map<String, Object> convert(JSON obj) throws ConversionException { + try { + return UtilGenerics.<Map<String, Object>>cast(obj.toObject(Map.class)); + } catch (IOException e) { + throw new ConversionException(e); + } + } + } + + public static class ListToJSON extends AbstractConverter<List<Object>, JSON> { + public ListToJSON() { + super(List.class, JSON.class); + } + + public JSON convert(List<Object> obj) throws ConversionException { + try { + return JSON.from(obj); + } catch (IOException e) { + throw new ConversionException(e); + } + } + } + + public static class MapToJSON extends AbstractConverter<Map<String, Object>, JSON> { + public MapToJSON() { + super(Map.class, JSON.class); + } + + public JSON convert(Map<String, Object> obj) throws ConversionException { + try { + return JSON.from(obj); + } catch (IOException e) { + throw new ConversionException(e); + } + } + } + + public void loadConverters() { + Converters.loadContainedConverters(JSONConverters.class); + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/JSONConverters.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NetConverters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NetConverters.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NetConverters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NetConverters.java Mon Aug 10 16:15:37 2015 @@ -1,137 +1,137 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; - -/** Net Converter classes. */ -public class NetConverters implements ConverterLoader { - public static final String module = NetConverters.class.getName(); - - public static class StringToInetAddress extends AbstractConverter<String, InetAddress> { - public StringToInetAddress() { - super(String.class, InetAddress.class); - } - - public InetAddress convert(String obj) throws ConversionException { - try { - return InetAddress.getByName(obj); - } catch (IOException e) { - throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); - } - } - } - - public static class InetAddressToString extends AbstractConverter<InetAddress, String> { - public InetAddressToString() { - super(InetAddress.class, String.class); - } - - public String convert(InetAddress obj) throws ConversionException { - String hostName = obj.getHostName(); - if (hostName != null) return hostName; - return obj.getHostAddress(); - } - } - - public static class StringToURI extends AbstractConverter<String, URI> { - public StringToURI() { - super(String.class, URI.class); - } - - public URI convert(String obj) throws ConversionException { - try { - return new URI(obj); - } catch (URISyntaxException e) { - throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); - } - } - } - - public static class URIToString extends AbstractConverter<URI, String> { - public URIToString() { - super(URI.class, String.class); - } - - public String convert(URI obj) throws ConversionException { - return obj.toString(); - } - } - - public static class StringToURL extends AbstractConverter<String, URL> { - public StringToURL() { - super(String.class, URL.class); - } - - public URL convert(String obj) throws ConversionException { - try { - return new URL(obj); - } catch (MalformedURLException e) { - throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); - } - } - } - - public static class URLToString extends AbstractConverter<URL, String> { - public URLToString() { - super(URL.class, String.class); - } - - public String convert(URL obj) throws ConversionException { - return obj.toString(); - } - } - - public static class URIToURL extends AbstractConverter<URI, URL> { - public URIToURL() { - super(URI.class, URL.class); - } - - public URL convert(URI obj) throws ConversionException { - try { - return obj.toURL(); - } catch (MalformedURLException e) { - throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); - } - } - } - - public static class URLToURI extends AbstractConverter<URL, URI> { - public URLToURI() { - super(URL.class, URI.class); - } - - public URI convert(URL obj) throws ConversionException { - try { - return obj.toURI(); - } catch (URISyntaxException e) { - throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); - } - } - } - - public void loadConverters() { - Converters.loadContainedConverters(NetConverters.class); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +/** Net Converter classes. */ +public class NetConverters implements ConverterLoader { + public static final String module = NetConverters.class.getName(); + + public static class StringToInetAddress extends AbstractConverter<String, InetAddress> { + public StringToInetAddress() { + super(String.class, InetAddress.class); + } + + public InetAddress convert(String obj) throws ConversionException { + try { + return InetAddress.getByName(obj); + } catch (IOException e) { + throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); + } + } + } + + public static class InetAddressToString extends AbstractConverter<InetAddress, String> { + public InetAddressToString() { + super(InetAddress.class, String.class); + } + + public String convert(InetAddress obj) throws ConversionException { + String hostName = obj.getHostName(); + if (hostName != null) return hostName; + return obj.getHostAddress(); + } + } + + public static class StringToURI extends AbstractConverter<String, URI> { + public StringToURI() { + super(String.class, URI.class); + } + + public URI convert(String obj) throws ConversionException { + try { + return new URI(obj); + } catch (URISyntaxException e) { + throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); + } + } + } + + public static class URIToString extends AbstractConverter<URI, String> { + public URIToString() { + super(URI.class, String.class); + } + + public String convert(URI obj) throws ConversionException { + return obj.toString(); + } + } + + public static class StringToURL extends AbstractConverter<String, URL> { + public StringToURL() { + super(String.class, URL.class); + } + + public URL convert(String obj) throws ConversionException { + try { + return new URL(obj); + } catch (MalformedURLException e) { + throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); + } + } + } + + public static class URLToString extends AbstractConverter<URL, String> { + public URLToString() { + super(URL.class, String.class); + } + + public String convert(URL obj) throws ConversionException { + return obj.toString(); + } + } + + public static class URIToURL extends AbstractConverter<URI, URL> { + public URIToURL() { + super(URI.class, URL.class); + } + + public URL convert(URI obj) throws ConversionException { + try { + return obj.toURL(); + } catch (MalformedURLException e) { + throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); + } + } + } + + public static class URLToURI extends AbstractConverter<URL, URI> { + public URLToURI() { + super(URL.class, URI.class); + } + + public URI convert(URL obj) throws ConversionException { + try { + return obj.toURI(); + } catch (URISyntaxException e) { + throw (ConversionException) new ConversionException(e.getMessage()).initCause(e); + } + } + } + + public void loadConverters() { + Converters.loadContainedConverters(NetConverters.class); + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NetConverters.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java Mon Aug 10 16:15:37 2015 @@ -1,75 +1,75 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion.test; - -import org.ofbiz.base.conversion.Converter; -import org.ofbiz.base.conversion.DateTimeConverters; -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.test.GenericTestCaseBase; - -import com.ibm.icu.util.Calendar; - -@SourceMonitored -public class DateTimeTests extends GenericTestCaseBase { - - public DateTimeTests(String name) { - super(name); - } - - public static <S, T> void assertConversion(String label, Converter<S, T> converter, S source, T target) throws Exception { - assertTrue(label + " can convert", converter.canConvert(source.getClass(), target.getClass())); - assertEquals(label + " converted", target, converter.convert(source)); - } - - public void testDateTimeConverters() throws Exception { - Calendar cal = Calendar.getInstance(); - long currentTime = cal.getTimeInMillis(); - cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); - cal.set(Calendar.MILLISECOND, 0); - long longTime = cal.getTimeInMillis(); // Start of day today - assertNotEquals("currentTime and longTime are not equal", currentTime, longTime); - java.util.Date utilDate = new java.util.Date(longTime); - java.sql.Date sqlDate = new java.sql.Date(longTime); - java.sql.Timestamp timestamp = new java.sql.Timestamp(longTime); - // Source class = java.util.Date - assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, longTime); - assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate, new java.sql.Date(longTime)); - assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate, utilDate.toString()); - assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate, timestamp); - // Source class = java.sql.Date - assertConversion("SqlDateToLong", new DateTimeConverters.DateToLong(), sqlDate, longTime); - assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate, utilDate); - assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate, sqlDate.toString()); - assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(), sqlDate, timestamp); - // Source class = java.sql.Timestamp - assertConversion("TimestampToLong", new DateTimeConverters.DateToLong(), timestamp, longTime); - assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp, utilDate); - assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(), timestamp, sqlDate); - assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp, timestamp.toString()); - // Source class = java.lang.Long - assertConversion("LongToDate", new DateTimeConverters.NumberToDate(), longTime, utilDate); - assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), longTime, sqlDate); - assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate); //Test conversion to start of day - assertConversion("LongToTimestamp", new DateTimeConverters.NumberToTimestamp(), longTime, timestamp); - // Source class = java.lang.String - assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(), timestamp); - //assertConversion("StringToDate", new DateTimeConverters.StringToDate(), utilDate.toString(), utilDate); - //assertConversion("StringToSqlDate", new DateTimeConverters.StringToSqlDate(), sqlDate.toString(), sqlDate); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion.test; + +import org.ofbiz.base.conversion.Converter; +import org.ofbiz.base.conversion.DateTimeConverters; +import org.ofbiz.base.lang.SourceMonitored; +import org.ofbiz.base.test.GenericTestCaseBase; + +import com.ibm.icu.util.Calendar; + +@SourceMonitored +public class DateTimeTests extends GenericTestCaseBase { + + public DateTimeTests(String name) { + super(name); + } + + public static <S, T> void assertConversion(String label, Converter<S, T> converter, S source, T target) throws Exception { + assertTrue(label + " can convert", converter.canConvert(source.getClass(), target.getClass())); + assertEquals(label + " converted", target, converter.convert(source)); + } + + public void testDateTimeConverters() throws Exception { + Calendar cal = Calendar.getInstance(); + long currentTime = cal.getTimeInMillis(); + cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + long longTime = cal.getTimeInMillis(); // Start of day today + assertNotEquals("currentTime and longTime are not equal", currentTime, longTime); + java.util.Date utilDate = new java.util.Date(longTime); + java.sql.Date sqlDate = new java.sql.Date(longTime); + java.sql.Timestamp timestamp = new java.sql.Timestamp(longTime); + // Source class = java.util.Date + assertConversion("DateToLong", new DateTimeConverters.DateToLong(), utilDate, longTime); + assertConversion("DateToSqlDate", new DateTimeConverters.DateToSqlDate(), utilDate, new java.sql.Date(longTime)); + assertConversion("DateToString", new DateTimeConverters.DateToString(), utilDate, utilDate.toString()); + assertConversion("DateToTimestamp", new DateTimeConverters.DateToTimestamp(), utilDate, timestamp); + // Source class = java.sql.Date + assertConversion("SqlDateToLong", new DateTimeConverters.DateToLong(), sqlDate, longTime); + assertConversion("SqlDateToDate", new DateTimeConverters.SqlDateToDate(), sqlDate, utilDate); + assertConversion("SqlDateToString", new DateTimeConverters.SqlDateToString(), sqlDate, sqlDate.toString()); + assertConversion("SqlDateToTimestamp", new DateTimeConverters.SqlDateToTimestamp(), sqlDate, timestamp); + // Source class = java.sql.Timestamp + assertConversion("TimestampToLong", new DateTimeConverters.DateToLong(), timestamp, longTime); + assertConversion("TimestampToDate", new DateTimeConverters.TimestampToDate(), timestamp, utilDate); + assertConversion("TimestampToSqlDate", new DateTimeConverters.TimestampToSqlDate(), timestamp, sqlDate); + assertConversion("TimestampToString", new DateTimeConverters.TimestampToString(), timestamp, timestamp.toString()); + // Source class = java.lang.Long + assertConversion("LongToDate", new DateTimeConverters.NumberToDate(), longTime, utilDate); + assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), longTime, sqlDate); + assertConversion("LongToSqlDate", new DateTimeConverters.NumberToSqlDate(), currentTime, sqlDate); //Test conversion to start of day + assertConversion("LongToTimestamp", new DateTimeConverters.NumberToTimestamp(), longTime, timestamp); + // Source class = java.lang.String + assertConversion("StringToTimestamp", new DateTimeConverters.StringToTimestamp(), timestamp.toString(), timestamp); + //assertConversion("StringToDate", new DateTimeConverters.StringToDate(), utilDate.toString(), utilDate); + //assertConversion("StringToSqlDate", new DateTimeConverters.StringToSqlDate(), sqlDate.toString(), sqlDate); + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/DateTimeTests.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java Mon Aug 10 16:15:37 2015 @@ -1,103 +1,103 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.conversion.test; - -import java.math.BigDecimal; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.conversion.Converter; -import org.ofbiz.base.conversion.ConverterLoader; -import org.ofbiz.base.conversion.Converters; -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.test.GenericTestCaseBase; -import org.ofbiz.base.util.UtilGenerics; -import org.ofbiz.base.util.UtilMisc; - -@SourceMonitored -public class MiscTests extends GenericTestCaseBase { - - public MiscTests(String name) { - super(name); - } - - public void testStaticHelperClass() throws Exception { - assertStaticHelperClass(Converters.class); - } - - public static class ConverterLoaderImpl implements ConverterLoader { - public void loadConverters() { - throw new RuntimeException(); - } - } - - public void testLoadContainedConvertersIgnoresException() { - Converters.loadContainedConverters(MiscTests.class); - } - - public static <S> void assertPassThru(Object wanted, Class<S> sourceClass) throws Exception { - assertPassThru(wanted, sourceClass, sourceClass); - } - - public static <S> void assertPassThru(Object wanted, Class<S> sourceClass, Class<? super S> targetClass) throws Exception { - Converter<S, ? super S> converter = Converters.getConverter(sourceClass, targetClass); - Object result = converter.convert(UtilGenerics.<S>cast(wanted)); - assertEquals("pass thru convert", wanted, result); - assertSame("pass thru exact equals", wanted, result); - assertTrue("pass thru can convert wanted", converter.canConvert(wanted.getClass(), targetClass)); - assertTrue("pass thru can convert source", converter.canConvert(sourceClass, targetClass)); - assertEquals("pass thru source class", wanted.getClass(), converter.getSourceClass()); - assertEquals("pass thru target class", targetClass, converter.getTargetClass()); - } - - public void testPassthru() throws Exception { - String string = "ofbiz"; - BigDecimal bigDecimal = new BigDecimal("1.234"); - URL url = new URL("http://ofbiz.apache.org"); - List<String> baseList = UtilMisc.toList("a", "1", "b", "2", "c", "3"); - ArrayList<String> arrayList = new ArrayList<String>(); - arrayList.addAll(baseList); - List<String> fastList = new LinkedList<String>(); - fastList.addAll(baseList); - Map<String, String> baseMap = UtilMisc.toMap("a", "1", "b", "2", "c", "3"); - HashMap<String, String> hashMap = new HashMap<String, String>(); - hashMap.putAll(baseMap); - Map<String, String> fastMap = new HashMap<String, String>(); - fastMap.putAll(baseMap); - Object[] testObjects = new Object[] { - string, - bigDecimal, - url, - arrayList, - fastList, - hashMap, - fastMap, - }; - for (Object testObject: testObjects) { - assertPassThru(testObject, testObject.getClass()); - } - assertPassThru(fastList, fastList.getClass(), List.class); - assertPassThru(fastMap, fastMap.getClass(), Map.class); - assertPassThru(hashMap, hashMap.getClass(), Map.class); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.conversion.test; + +import java.math.BigDecimal; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.ofbiz.base.conversion.Converter; +import org.ofbiz.base.conversion.ConverterLoader; +import org.ofbiz.base.conversion.Converters; +import org.ofbiz.base.lang.SourceMonitored; +import org.ofbiz.base.test.GenericTestCaseBase; +import org.ofbiz.base.util.UtilGenerics; +import org.ofbiz.base.util.UtilMisc; + +@SourceMonitored +public class MiscTests extends GenericTestCaseBase { + + public MiscTests(String name) { + super(name); + } + + public void testStaticHelperClass() throws Exception { + assertStaticHelperClass(Converters.class); + } + + public static class ConverterLoaderImpl implements ConverterLoader { + public void loadConverters() { + throw new RuntimeException(); + } + } + + public void testLoadContainedConvertersIgnoresException() { + Converters.loadContainedConverters(MiscTests.class); + } + + public static <S> void assertPassThru(Object wanted, Class<S> sourceClass) throws Exception { + assertPassThru(wanted, sourceClass, sourceClass); + } + + public static <S> void assertPassThru(Object wanted, Class<S> sourceClass, Class<? super S> targetClass) throws Exception { + Converter<S, ? super S> converter = Converters.getConverter(sourceClass, targetClass); + Object result = converter.convert(UtilGenerics.<S>cast(wanted)); + assertEquals("pass thru convert", wanted, result); + assertSame("pass thru exact equals", wanted, result); + assertTrue("pass thru can convert wanted", converter.canConvert(wanted.getClass(), targetClass)); + assertTrue("pass thru can convert source", converter.canConvert(sourceClass, targetClass)); + assertEquals("pass thru source class", wanted.getClass(), converter.getSourceClass()); + assertEquals("pass thru target class", targetClass, converter.getTargetClass()); + } + + public void testPassthru() throws Exception { + String string = "ofbiz"; + BigDecimal bigDecimal = new BigDecimal("1.234"); + URL url = new URL("http://ofbiz.apache.org"); + List<String> baseList = UtilMisc.toList("a", "1", "b", "2", "c", "3"); + ArrayList<String> arrayList = new ArrayList<String>(); + arrayList.addAll(baseList); + List<String> fastList = new LinkedList<String>(); + fastList.addAll(baseList); + Map<String, String> baseMap = UtilMisc.toMap("a", "1", "b", "2", "c", "3"); + HashMap<String, String> hashMap = new HashMap<String, String>(); + hashMap.putAll(baseMap); + Map<String, String> fastMap = new HashMap<String, String>(); + fastMap.putAll(baseMap); + Object[] testObjects = new Object[] { + string, + bigDecimal, + url, + arrayList, + fastList, + hashMap, + fastMap, + }; + for (Object testObject: testObjects) { + assertPassThru(testObject, testObject.getClass()); + } + assertPassThru(fastList, fastList.getClass(), List.class); + assertPassThru(fastMap, fastMap.getClass(), Map.class); + assertPassThru(hashMap, hashMap.getClass(), Map.class); + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/test/MiscTests.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/IsEmpty.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/IsEmpty.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/IsEmpty.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/IsEmpty.java Mon Aug 10 16:15:37 2015 @@ -1,23 +1,23 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.ofbiz.base.lang; - -public interface IsEmpty { - boolean isEmpty(); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ofbiz.base.lang; + +public interface IsEmpty { + boolean isEmpty(); +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/IsEmpty.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/LockedBy.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/LockedBy.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/LockedBy.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/LockedBy.java Mon Aug 10 16:15:37 2015 @@ -1,37 +1,37 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.ofbiz.base.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** This annotation is meant to be used to describe how some variable - * or method is protected by some other locking mechanism. Its value - * is free-form, and can contain anything. It will generally contain - * the name of an instance variable, including <code>this</code>. - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD}) -public @interface LockedBy { - String value(); -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ofbiz.base.lang; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** This annotation is meant to be used to describe how some variable + * or method is protected by some other locking mechanism. Its value + * is free-form, and can contain anything. It will generally contain + * the name of an instance variable, including <code>this</code>. + */ +@Documented +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD}) +public @interface LockedBy { + String value(); +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/LockedBy.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/SourceMonitored.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/SourceMonitored.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/SourceMonitored.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/SourceMonitored.java Mon Aug 10 16:15:37 2015 @@ -1,29 +1,29 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.lang; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE}) -public @interface SourceMonitored { -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.lang; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE}) +public @interface SourceMonitored { +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/SourceMonitored.java ('svn:eol-style' removed) Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/test/ComparableRangeTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/test/ComparableRangeTests.java?rev=1695126&r1=1695125&r2=1695126&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/test/ComparableRangeTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/test/ComparableRangeTests.java Mon Aug 10 16:15:37 2015 @@ -1,128 +1,128 @@ -/******************************************************************************* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - *******************************************************************************/ -package org.ofbiz.base.lang.test; - -import org.ofbiz.base.test.GenericTestCaseBase; -import org.ofbiz.base.lang.ComparableRange; -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.UtilGenerics; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -@SourceMonitored -public class ComparableRangeTests extends GenericTestCaseBase { - - public ComparableRangeTests(String name) { - super(name); - } - - @SuppressWarnings("unchecked") - private static <L extends Comparable<L>, R extends Comparable<R>> void comparableRangeConstructorTest(L left, R right) { - new ComparableRange<L>(left, left); - new ComparableRange<R>(right, right); - IllegalArgumentException caught = null; - try { - new ComparableRange(left, right); - } catch (IllegalArgumentException e) { - caught = e; - } finally { - assertNotNull("expected exception", caught); - } - caught = null; - try { - new ComparableRange(right, left); - } catch (IllegalArgumentException e) { - caught = e; - } finally { - assertNotNull("expected exception", caught); - } - } - - private static <T extends Comparable<T>, B extends Comparable<B>> void comparableRangeTest(String label, B bad, T a, T b, T c, T d) { - comparableRangeConstructorTest(bad, a); - assertTrue(label + ":a-isPoint", new ComparableRange<T>(a, a).isPoint()); - assertTrue(label + ":b-isPoint", new ComparableRange<T>(b, b).isPoint()); - assertTrue(label + ":c-isPoint", new ComparableRange<T>(c, c).isPoint()); - ComparableRange<T> first = new ComparableRange<T>(a, b); - ComparableRange<T> second = new ComparableRange<T>(c, d); - ComparableRange<T> all = new ComparableRange<T>(a, d); - assertEquals(label + ":a-b toString", a + " - " + b, first.toString()); - assertEquals(label + ":c-d toString", c + " - " + d, second.toString()); - assertEquals(label + ":a-d toString", a + " - " + d, all.toString()); - assertFalse(label + ":a-b isPoint", first.isPoint()); - assertFalse(label + ":c-d isPoint", second.isPoint()); - assertFalse(label + ":a-d isPoint", all.isPoint()); - assertEquals(label + ":a-b == a-b", first, first); - assertEquals(label + ":a-b.compareTo(a-b)", 0, first.compareTo(first)); - assertEquals(label + ":a-b equals a-b", first, new ComparableRange<T>(a, b)); - assertEquals(label + ":a-b.compareTo(new a-b)", 0, first.compareTo(new ComparableRange<T>(a, b))); - assertEquals(label + ":a-b equals b-a", first, new ComparableRange<T>(b, a)); - assertEquals(label + ":a-b.compareTo(new b-a)", 0, first.compareTo(new ComparableRange<T>(b, a))); - assertNotEquals(label + ":a-b not-equal other", first, ComparableRangeTests.class); - assertFalse(label + ":a-d equals null", all.equals(null)); - ClassCastException caught = null; - try { - UtilGenerics.<Comparable<Object>>cast(first).compareTo(ComparableRangeTests.class); - } catch (ClassCastException e) { - caught = e; - } finally { - assertNotNull(label + " compareTo CCE", caught); - } - assertNotEquals(label + ":a-a != a-b", new ComparableRange<T>(a, a), first); - assertThat(label + ":a-a.compareTo(a-b) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(first))); - assertNotEquals(label + ":a-a != c-d", new ComparableRange<T>(a, a), second); - assertThat(label + ":a-a.compareTo(c-d) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(second))); - assertNotEquals(label + ":a-a != a-d", new ComparableRange<T>(a, a), all); - assertThat(label + ":a-a.compareTo(a-d) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(all))); - assertTrue(label + ":b-c after a-b", second.after(first)); - assertThat(label + ":b-c.compareTo(a-b)", 0, lessThan(second.compareTo(first))); - assertFalse(label + ":c-d !after c-d", second.after(second)); - assertEquals(label + ":c-d.compareTo(c-d)", 0, second.compareTo(second)); - assertTrue(label + ":a-b before c-d", first.before(second)); - assertThat(label + ":a-b.compareTo(c-d)", 0, greaterThan(first.compareTo(second))); - assertFalse(label + ":a-b !before a-b", first.before(first)); - assertEquals(label + ":a-b.compareTo(a-b)", 0, first.compareTo(first)); - assertTrue(label + ":a-d includes a-b", all.includes(first)); - assertTrue(label + ":a-b overlaps b-c", first.overlaps(new ComparableRange<T>(b, c))); - assertTrue(label + ":b-c overlaps c-d", new ComparableRange<T>(b, c).overlaps(second)); - assertTrue(label + ":a-b overlaps a-d", first.overlaps(all)); - assertTrue(label + ":a-d overlaps a-b", all.overlaps(first)); - assertTrue(label + ":a-d overlaps b-c", all.overlaps(new ComparableRange<T>(b, c))); - assertTrue(label + ":b-c overlaps a-d", new ComparableRange<T>(b, c).overlaps(all)); - assertFalse(label + ":a-b overlaps c-d", first.overlaps(second)); - assertFalse(label + ":c-d overlaps a-b", second.overlaps(first)); - assertTrue(label + ":a-b includes a", first.includes(a)); - assertTrue(label + ":a-b includes b", first.includes(b)); - assertFalse(label + ":a-b includes c", first.includes(c)); - assertFalse(label + ":a includes a-b", new ComparableRange<T>(a, a).includes(first)); - assertTrue(label + ":c-d after a", second.after(a)); - assertTrue(label + ":c-d after b", second.after(b)); - assertFalse(label + ":c-d after c", second.after(c)); - assertFalse(label + ":c-d after d", second.after(d)); - assertFalse(label + ":a-b after a", first.before(a)); - assertFalse(label + ":a-b after b", first.before(b)); - assertTrue(label + ":a-b after c", first.before(c)); - assertTrue(label + ":a-b after d", first.before(d)); - } - - public void testComparableRange() { - comparableRangeTest("integer", 20L, 1, 2, 3, 4); - } -} +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.base.lang.test; + +import org.ofbiz.base.test.GenericTestCaseBase; +import org.ofbiz.base.lang.ComparableRange; +import org.ofbiz.base.lang.SourceMonitored; +import org.ofbiz.base.util.UtilGenerics; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +@SourceMonitored +public class ComparableRangeTests extends GenericTestCaseBase { + + public ComparableRangeTests(String name) { + super(name); + } + + @SuppressWarnings("unchecked") + private static <L extends Comparable<L>, R extends Comparable<R>> void comparableRangeConstructorTest(L left, R right) { + new ComparableRange<L>(left, left); + new ComparableRange<R>(right, right); + IllegalArgumentException caught = null; + try { + new ComparableRange(left, right); + } catch (IllegalArgumentException e) { + caught = e; + } finally { + assertNotNull("expected exception", caught); + } + caught = null; + try { + new ComparableRange(right, left); + } catch (IllegalArgumentException e) { + caught = e; + } finally { + assertNotNull("expected exception", caught); + } + } + + private static <T extends Comparable<T>, B extends Comparable<B>> void comparableRangeTest(String label, B bad, T a, T b, T c, T d) { + comparableRangeConstructorTest(bad, a); + assertTrue(label + ":a-isPoint", new ComparableRange<T>(a, a).isPoint()); + assertTrue(label + ":b-isPoint", new ComparableRange<T>(b, b).isPoint()); + assertTrue(label + ":c-isPoint", new ComparableRange<T>(c, c).isPoint()); + ComparableRange<T> first = new ComparableRange<T>(a, b); + ComparableRange<T> second = new ComparableRange<T>(c, d); + ComparableRange<T> all = new ComparableRange<T>(a, d); + assertEquals(label + ":a-b toString", a + " - " + b, first.toString()); + assertEquals(label + ":c-d toString", c + " - " + d, second.toString()); + assertEquals(label + ":a-d toString", a + " - " + d, all.toString()); + assertFalse(label + ":a-b isPoint", first.isPoint()); + assertFalse(label + ":c-d isPoint", second.isPoint()); + assertFalse(label + ":a-d isPoint", all.isPoint()); + assertEquals(label + ":a-b == a-b", first, first); + assertEquals(label + ":a-b.compareTo(a-b)", 0, first.compareTo(first)); + assertEquals(label + ":a-b equals a-b", first, new ComparableRange<T>(a, b)); + assertEquals(label + ":a-b.compareTo(new a-b)", 0, first.compareTo(new ComparableRange<T>(a, b))); + assertEquals(label + ":a-b equals b-a", first, new ComparableRange<T>(b, a)); + assertEquals(label + ":a-b.compareTo(new b-a)", 0, first.compareTo(new ComparableRange<T>(b, a))); + assertNotEquals(label + ":a-b not-equal other", first, ComparableRangeTests.class); + assertFalse(label + ":a-d equals null", all.equals(null)); + ClassCastException caught = null; + try { + UtilGenerics.<Comparable<Object>>cast(first).compareTo(ComparableRangeTests.class); + } catch (ClassCastException e) { + caught = e; + } finally { + assertNotNull(label + " compareTo CCE", caught); + } + assertNotEquals(label + ":a-a != a-b", new ComparableRange<T>(a, a), first); + assertThat(label + ":a-a.compareTo(a-b) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(first))); + assertNotEquals(label + ":a-a != c-d", new ComparableRange<T>(a, a), second); + assertThat(label + ":a-a.compareTo(c-d) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(second))); + assertNotEquals(label + ":a-a != a-d", new ComparableRange<T>(a, a), all); + assertThat(label + ":a-a.compareTo(a-d) < 0", 0, greaterThan(new ComparableRange<T>(a, a).compareTo(all))); + assertTrue(label + ":b-c after a-b", second.after(first)); + assertThat(label + ":b-c.compareTo(a-b)", 0, lessThan(second.compareTo(first))); + assertFalse(label + ":c-d !after c-d", second.after(second)); + assertEquals(label + ":c-d.compareTo(c-d)", 0, second.compareTo(second)); + assertTrue(label + ":a-b before c-d", first.before(second)); + assertThat(label + ":a-b.compareTo(c-d)", 0, greaterThan(first.compareTo(second))); + assertFalse(label + ":a-b !before a-b", first.before(first)); + assertEquals(label + ":a-b.compareTo(a-b)", 0, first.compareTo(first)); + assertTrue(label + ":a-d includes a-b", all.includes(first)); + assertTrue(label + ":a-b overlaps b-c", first.overlaps(new ComparableRange<T>(b, c))); + assertTrue(label + ":b-c overlaps c-d", new ComparableRange<T>(b, c).overlaps(second)); + assertTrue(label + ":a-b overlaps a-d", first.overlaps(all)); + assertTrue(label + ":a-d overlaps a-b", all.overlaps(first)); + assertTrue(label + ":a-d overlaps b-c", all.overlaps(new ComparableRange<T>(b, c))); + assertTrue(label + ":b-c overlaps a-d", new ComparableRange<T>(b, c).overlaps(all)); + assertFalse(label + ":a-b overlaps c-d", first.overlaps(second)); + assertFalse(label + ":c-d overlaps a-b", second.overlaps(first)); + assertTrue(label + ":a-b includes a", first.includes(a)); + assertTrue(label + ":a-b includes b", first.includes(b)); + assertFalse(label + ":a-b includes c", first.includes(c)); + assertFalse(label + ":a includes a-b", new ComparableRange<T>(a, a).includes(first)); + assertTrue(label + ":c-d after a", second.after(a)); + assertTrue(label + ":c-d after b", second.after(b)); + assertFalse(label + ":c-d after c", second.after(c)); + assertFalse(label + ":c-d after d", second.after(d)); + assertFalse(label + ":a-b after a", first.before(a)); + assertFalse(label + ":a-b after b", first.before(b)); + assertTrue(label + ":a-b after c", first.before(c)); + assertTrue(label + ":a-b after d", first.before(d)); + } + + public void testComparableRange() { + comparableRangeTest("integer", 20L, 1, 2, 3, 4); + } +} Propchange: ofbiz/trunk/framework/base/src/org/ofbiz/base/lang/test/ComparableRangeTests.java ('svn:eol-style' removed) |
Free forum by Nabble | Edit this page |