Increase test coverage.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 14:04:37 +0000 (16:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 14:04:37 +0000 (16:04 +0200)
src/test/java/net/pterodactylus/sone/core/UpdateCheckerTest.java

index fb2b9f2..b3f8c08 100644 (file)
@@ -93,6 +93,7 @@ public class UpdateCheckerTest {
                assertThat(updateFoundEvent.getValue().releaseTime(), is(11865368297000L));
                assertThat(updateChecker.getLatestVersion(), is(new Version(99, 0, 0)));
                assertThat(updateChecker.getLatestVersionDate(), is(11865368297000L));
+               assertThat(updateChecker.hasLatestVersion(), is(true));
        }
 
        private FetchResult createFutureFetchResult() {
@@ -198,4 +199,35 @@ public class UpdateCheckerTest {
                return new FetchResult(clientMetadata, fetched);
        }
 
+       @Test
+       public void invalidPropertiesDoesNotCauseAnUpdateToBeFound() {
+               setupFetchResult(createMissingTimeFetchResult());
+               setupCallbackWithEdition(MAX_VALUE, true, false);
+               verifyAFreenetUriIsFetched();
+               verifyNoUpdateFoundEventIsFired();
+       }
+
+       private FetchResult createMissingTimeFetchResult() {
+               ClientMetadata clientMetadata = new ClientMetadata("application/xml");
+               Bucket fetched = new StringBucket("# MapConfigurationBackendVersion=1\n" +
+                               "CurrentVersion/Version: 0.2\n");
+               return new FetchResult(clientMetadata, fetched);
+       }
+
+       @Test
+       public void invalidVersionDoesNotCauseAnUpdateToBeFound() {
+               setupFetchResult(createInvalidVersionFetchResult());
+               setupCallbackWithEdition(MAX_VALUE, true, false);
+               verifyAFreenetUriIsFetched();
+               verifyNoUpdateFoundEventIsFired();
+       }
+
+       private FetchResult createInvalidVersionFetchResult() {
+               ClientMetadata clientMetadata = new ClientMetadata("application/xml");
+               Bucket fetched = new StringBucket("# MapConfigurationBackendVersion=1\n" +
+                               "CurrentVersion/Version: foo\n" +
+                               "CurrentVersion/ReleaseTime: 1289417883000");
+               return new FetchResult(clientMetadata, fetched);
+       }
+
 }