diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..87d1760 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: java +jdk: + - openjdk8 + - openjdk11 +install: {} +script: + - ./gradlew assemble check + +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ + +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ + diff --git a/README.md b/README.md index 83bc846..0378137 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![License LGPLv3][LGPLv3 badge]][LGPLv3] +[![License ASL 2.0][ASL 2.0 badge]][ASL 2.0] +[![Build Status][Travis badge]][Travis] +[![Maven Central][Maven Central badge]][Maven] + ## Read me first This project, as of version 1.0, is licensed under both LGPLv3 and ASL 2.0. See @@ -25,19 +30,21 @@ See below for more. ## Versions -The current version is **1.1**. Javadoc [here](http://fge.github.io/msg-simple/index.html). +The current version is **1.2**. Javadoc [here](https://java-json-tools.github.io/msg-simple/index.html). See [here](https://github.com/fge/msg-simple/wiki/Examples) for sample API usage. ## Downloads and Maven artifact -You can download the jar directly on [Bintray](https://bintray.com/fge/maven/msg-simple). +Versions before 1.2 are available at `groupId` `com.github.fge`. + +**OBSOLETE** You can download the jar directly on [Bintray](https://bintray.com/fge/maven/msg-simple). For Gradle: ```gradle dependencies { - compile(group: "com.github.fge", name: "msg-simple", version: "yourVersionHere"); + compile(group: "com.github.java-json-tools", name: "msg-simple", version: "yourVersionHere"); } ``` @@ -45,7 +52,7 @@ For Maven: ```xml - com.github.fge + com.github.java-json-tools msg-simple your-version-here @@ -65,3 +72,12 @@ This library currently has the following features: The roadmap for future versions can be found [here](https://github.com/fge/msg-simple/wiki/Roadmap). Feature requests are of course welcome! +[LGPLv3 badge]: https://img.shields.io/:license-LGPLv3-blue.svg +[LGPLv3]: http://www.gnu.org/licenses/lgpl-3.0.html +[ASL 2.0 badge]: https://img.shields.io/:license-Apache%202.0-blue.svg +[ASL 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html +[Travis Badge]: https://api.travis-ci.org/java-json-tools/msg-simple.svg?branch=master +[Travis]: https://travis-ci.org/java-json-tools/msg-simple +[Maven Central badge]: https://img.shields.io/maven-central/v/com.github.java-json-tools/msg-simple.svg +[Maven]: https://search.maven.org/artifact/com.github.java-json-tools/msg-simple + diff --git a/build.gradle b/build.gradle index 54cfa20..e05fb56 100644 --- a/build.gradle +++ b/build.gradle @@ -17,46 +17,61 @@ * - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt */ -/* - * This has to be here... It will not be taken into account in common.gradle! - * - * Looks like a serious bug... See also: - * - * http://forums.gradle.org/gradle/topics/buildscript_in_subprojects_ignored - */ -//buildscript { -// repositories { -// maven { -// url "http://repo.springsource.org/plugins-release"; -// } -// } -// dependencies { -// classpath(group: "org.springframework.build.gradle", -// name: "propdeps-plugin", version: "0.0.5"); -// } -//}; -// -//configure(allprojects) { -// apply(plugin: "propdeps"); -// apply(plugin: "propdeps-maven"); -// apply(plugin: "propdeps-idea"); -// apply(plugin: "propdeps-eclipse"); -//} +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.2.0' + } +} + +plugins { + id("net.ltgt.errorprone") version "0.8.1" apply false +} apply(plugin: "java"); apply(plugin: "maven"); apply(plugin: "signing"); -apply(plugin: "osgi"); +apply(plugin: "biz.aQute.bnd.builder"); apply(plugin: "idea"); apply(plugin: "eclipse"); +apply(plugin: "net.ltgt.errorprone"); apply(from: "project.gradle"); +group = "com.github.java-json-tools"; + +ext.forRelease = !version.endsWith("-SNAPSHOT"); + /* * Repositories to use */ repositories { mavenCentral(); + if (!forRelease) { + maven { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + } + /* Allow staging references for last pre-release testing. */ + if (project.properties.containsKey("sonatypeUsername")) { + maven { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + credentials { + username = project.properties["sonatypeUsername"] + password = project.properties["sonatypePassword"] + } + } + } +} + +/* + * Add errorprone checking. + */ +dependencies { + errorprone("com.google.errorprone:error_prone_core:2.3.3") + errorproneJavac("com.google.errorprone:javac:9+181-r4173-1") } /* @@ -69,6 +84,15 @@ test { useTestNG() { useDefaultListeners = true; }; + // Since Travis-CI logs aren't available, put failure information + // into Gradle output directly. + testLogging { + events "failed" + exceptionFormat "full" + } + systemProperties = [ + "java.locale.providers": "CLDR,COMPAT", + ] } /* @@ -79,6 +103,20 @@ task sourcesJar(type: Jar, dependsOn: classes) { from sourceSets.main.allSource; } +/* + * Lint all the things! + */ +allprojects { + gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + options.compilerArgs << "-Xlint:all" << "-Werror" + } + tasks.withType(Javadoc) { + options.addStringOption('Xwerror', '-quiet') + } + } +} + /* * Javadoc: we need to tell where the overview.html is, it will not pick it up * automatically... @@ -99,13 +137,15 @@ artifacts { archives javadocJar; } -task wrapper(type: Wrapper) { - gradleVersion = "1.11"; - distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"; +wrapper { + gradleVersion = "5.6.3"; + distributionUrl = "https://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"; } -task pom << { - pom {}.writeTo("${projectDir}/pom.xml"); +task pom { + doLast { + pom {}.writeTo("${projectDir}/pom.xml"); + } } /* @@ -113,25 +153,27 @@ task pom << { */ project.ext { - gitrwscm = sprintf("git@github.com:fge/%s", name); - gitroscm = sprintf("https://github.com/fge/%s.git", name); - projectURL = sprintf("https://github.com/fge/%s", name); + description = "A lightweight, UTF-8 capable, printf() capable alternative to Java's ResourceBundle"; + scmUrl = sprintf("git@github.com:java-json-tools/%s.git", name) + projectURL = sprintf("https://github.com/java-json-tools/%s", name); sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"; sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"; }; -task checkSigningRequirements << { - def requiredProperties = [ "sonatypeUsername", "sonatypePassword" ]; - def noDice = false; - requiredProperties.each { - if (project.properties[it] == null) { - noDice = true; - System.err.printf("property \"%s\" is not defined!") +task checkSigningRequirements { + doLast { + def requiredProperties = [ "sonatypeUsername", "sonatypePassword" ]; + def noDice = false; + requiredProperties.each { + if (project.properties[it] == null) { + noDice = true; + System.err.printf("property \"%s\" is not defined!") + } } + if (noDice) + throw new IllegalStateException("missing required properties for " + + "upload"); } - if (noDice) - throw new IllegalStateException("missing required properties for " + - "upload"); } uploadArchives { @@ -167,15 +209,15 @@ uploadArchives { uploadArchives.repositories.mavenDeployer ]*.pom*.whenConfigured { pom -> pom.project { - name "${name}"; + name "${project.name}"; packaging "jar"; - description "${description}"; + description "${project.ext.description}"; url "${projectURL}"; scm { - url "${gitrwscm}"; - connection "${gitrwscm}"; - developerConnection "${gitroscm}"; + url "${scmUrl}"; + connection "${scmUrl}"; + developerConnection "scm:git:${scmUrl}"; } licenses { @@ -193,15 +235,14 @@ uploadArchives { developers { developer { - id "fge"; - name "Francis Galiegue"; - email "fgaliegue@gmail.com"; + id "huggsboson"; + name "John Huffaker"; + email "jhuffaker+java-json-tools@gmail.com"; } } } } -ext.forRelease = !version.endsWith("-SNAPSHOT"); signing { required { forRelease && gradle.taskGraph.hasTask("uploadArchives") }; sign configurations.archives; diff --git a/dorelease.sh b/dorelease.sh index decafaa..34b99f9 100755 --- a/dorelease.sh +++ b/dorelease.sh @@ -1,4 +1,4 @@ #!/bin/bash -./gradlew --recompile-scripts clean test uploadArchives +./gradlew --refresh-dependencies clean test uploadArchives diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 3c7abdf..5c2d1cf 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e6f4fd3..3a54a33 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,25 +1,5 @@ -# -# Copyright (c) 2014, Francis Galiegue (fgaliegue@gmail.com) -# -# This software is dual-licensed under: -# -# - the Lesser General Public License (LGPL) version 3.0 or, at your option, any -# later version; -# - the Apache Software License (ASL) version 2.0. -# -# The text of this file and of both licenses is available at the root of this -# project or, if you have the jar distribution, in directory META-INF/, under -# the names LGPL-3.0.txt and ASL-2.0.txt respectively. -# -# Direct link to the sources: -# -# - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt -# - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt -# - -#Sat Apr 12 21:17:48 CEST 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip diff --git a/gradlew b/gradlew index 91a7e26..83f2acf 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,20 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed 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 +# +# https://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. +# ############################################################################## ## @@ -6,20 +22,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +64,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +75,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +105,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -110,10 +125,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +170,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec9973..24467a1 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -8,14 +24,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +62,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +75,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/project.gradle b/project.gradle index 9e7e5fa..b42aac6 100644 --- a/project.gradle +++ b/project.gradle @@ -20,20 +20,16 @@ /* * Project-specific settings. Unfortunately we cannot put the name in there! */ -group = "com.github.fge"; -version = "1.2-SNAPSHOT"; -sourceCompatibility = "1.6"; -targetCompatibility = "1.6"; // defaults to sourceCompatibility - -project.ext { - description = "A lightweight, fully compatible, UTF-8/printf() capable alternative to Java's ResourceBundle"; -}; +group = "com.github.java-json-tools"; +version = "1.3-SNAPSHOT"; +sourceCompatibility = JavaVersion.VERSION_1_7; +targetCompatibility = JavaVersion.VERSION_1_7; // defaults to sourceCompatibility /* * List of dependencies */ dependencies { - compile(group: "com.github.fge", name: "btf", version: "1.2"); + compile(group: "com.github.java-json-tools", name: "btf", version: "1.3"); compile(group: "com.google.code.findbugs", name: "jsr305", version: "2.0.1"); testCompile(group: "org.testng", name: "testng", version: "6.8.7") { @@ -41,10 +37,18 @@ dependencies { exclude(group: "org.beanshell", module: "bsh"); exclude(group: "org.yaml", module: "snakeyaml"); }; - testCompile(group: "org.mockito", name: "mockito-core", version: "1.9.5"); + testCompile(group: "org.mockito", name: "mockito-core", version: "2.28.2"); } -javadoc.options.links("http://docs.oracle.com/javase/6/docs/api/"); -javadoc.options.links("http://jsr-305.googlecode.com/svn/trunk/javadoc/"); -javadoc.options.links("http://fge.github.io/btf/"); - +javadoc { + options { + def currentJavaVersion = org.gradle.api.JavaVersion.current() + // FIXME: https://github.com/gradle/gradle/issues/11182 + if (currentJavaVersion.compareTo(org.gradle.api.JavaVersion.VERSION_1_9) >= 0) { + addStringOption("-release", "7"); + } + links("https://docs.oracle.com/javase/7/docs/api/"); + links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.1/"); + links("https://java-json-tools.github.io/btf/"); + } +} diff --git a/src/main/java/com/github/fge/msgsimple/bundle/MessageBundle.java b/src/main/java/com/github/fge/msgsimple/bundle/MessageBundle.java index 9e9611d..873d104 100644 --- a/src/main/java/com/github/fge/msgsimple/bundle/MessageBundle.java +++ b/src/main/java/com/github/fge/msgsimple/bundle/MessageBundle.java @@ -201,6 +201,7 @@ public String printf(final String key, final Object... params) * @param params the format parameters * @return the formatted message */ + @SuppressWarnings("JdkObsolete") public String format(final Locale locale, final String key, final Object... params) { diff --git a/src/main/java/com/github/fge/msgsimple/bundle/MessageBundleBuilder.java b/src/main/java/com/github/fge/msgsimple/bundle/MessageBundleBuilder.java index b488197..e4b8693 100644 --- a/src/main/java/com/github/fge/msgsimple/bundle/MessageBundleBuilder.java +++ b/src/main/java/com/github/fge/msgsimple/bundle/MessageBundleBuilder.java @@ -122,6 +122,7 @@ public MessageBundleBuilder prependSource(final MessageSource source) /** * Convenience method to append a single-source provider for a given locale * + * @param locale the locale * @param source the message source * @return this * @see StaticMessageSourceProvider#withSingleSource(Locale, MessageSource) @@ -138,6 +139,7 @@ public MessageBundleBuilder appendSource(final Locale locale, /** * Convenience method to prepend a single-source provider for a given locale * + * @param locale the locale * @param source the message source * @return this * @see StaticMessageSourceProvider#withSingleSource(Locale, MessageSource) diff --git a/src/main/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProvider.java b/src/main/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProvider.java index 7eff6df..ba279ed 100644 --- a/src/main/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProvider.java +++ b/src/main/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProvider.java @@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; /** * A caching, on-demand loading message source provider with configurable expiry @@ -84,11 +85,14 @@ public final class LoadingMessageSourceProvider private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() { private final ThreadFactory factory = Executors.defaultThreadFactory(); + private final AtomicLong count = new AtomicLong(0); @Override public Thread newThread(final Runnable r) { final Thread ret = factory.newThread(r); + ret.setName(String.format(Locale.ROOT, "LoadingMessageSourceProvider-%d", + count.getAndIncrement())); ret.setDaemon(true); return ret; } @@ -249,6 +253,7 @@ public MessageSource call() }); } + @SuppressWarnings("FutureReturnValueIgnored") private void setupExpiry(final long duration, final TimeUnit unit) { final Runnable runnable = new Runnable() diff --git a/src/test/java/com/github/fge/msgsimple/bundle/MessageBundleTest.java b/src/test/java/com/github/fge/msgsimple/bundle/MessageBundleTest.java index 13db79c..11bb075 100644 --- a/src/test/java/com/github/fge/msgsimple/bundle/MessageBundleTest.java +++ b/src/test/java/com/github/fge/msgsimple/bundle/MessageBundleTest.java @@ -373,7 +373,7 @@ public Iterator msgFormatData() "{0,number,integer}."; arguments = new Object[] { 7, calendar.getTime(), "a disturbance in the Force" }; - expected = "At 12:30:00 PM on Jul 3, 2053, there was a disturbance in" + + expected = "At 12:30:00 on 2053 Jul 3, there was a disturbance in" + " the Force on planet 7."; list.add(new Object[] { format, arguments, expected }); diff --git a/src/test/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProviderTest.java b/src/test/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProviderTest.java index cb8a54f..08c8c49 100644 --- a/src/test/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProviderTest.java +++ b/src/test/java/com/github/fge/msgsimple/provider/LoadingMessageSourceProviderTest.java @@ -37,6 +37,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import static org.testng.Assert.*; @@ -285,11 +286,11 @@ public void expiryCausesFailedLoadsToRetry() .thenReturn(source); final MessageSourceProvider provider = builder.setLoader(loader) - .setExpiryTime(10L, TimeUnit.MILLISECONDS) + .setExpiryTime(100L, TimeUnit.MILLISECONDS) .setDefaultSource(defaultSource).build(); final MessageSource before = provider.getMessageSource(Locale.ROOT); - TimeUnit.MILLISECONDS.sleep(50L); + TimeUnit.MILLISECONDS.sleep(500L); final MessageSource after = provider.getMessageSource(Locale.ROOT); verify(loader, times(2)).load(Locale.ROOT);