/*
 * Copyright 2017 Lukáš Petrovický
 *
 * 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
 *
 *     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 com.github.triceo.robozonky.notifications.email;

import java.util.UUID;

import com.github.triceo.robozonky.api.State;
import org.assertj.core.api.Assertions;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

public class BalanceTrackerTest {

    @After
    public void deleteBalance() {
        BalanceTracker.INSTANCE.reset();
    }

    @Before
    public void makeSureNoState() {
        final State.ClassSpecificState state = State.INSTANCE.forClass(BalanceTracker.class);
        Assume.assumeFalse(state.getValue(BalanceTracker.BALANCE_KEY).isPresent());
    }

    @Test
    public void lifecycle() {
        final State.ClassSpecificState state = State.INSTANCE.forClass(BalanceTracker.class);
        Assume.assumeFalse(state.getValue(BalanceTracker.BALANCE_KEY).isPresent());
        Assertions.assertThat(BalanceTracker.INSTANCE.getLastKnownBalance()).isEmpty();
        final int newBalance = 200;
        BalanceTracker.INSTANCE.setLastKnownBalance(newBalance);
        Assertions.assertThat(BalanceTracker.INSTANCE.getLastKnownBalance()).isPresent().hasValue(newBalance);
        Assertions.assertThat(state.getValue(BalanceTracker.BALANCE_KEY)).isPresent();
        Assertions.assertThat(BalanceTracker.INSTANCE.reset()).isTrue();
        Assertions.assertThat(BalanceTracker.INSTANCE.getLastKnownBalance()).isEmpty();
    }

    @Test
    public void wrongData() {
        final State.ClassSpecificState state = State.INSTANCE.forClass(BalanceTracker.class);
        state.setValue(BalanceTracker.BALANCE_KEY, UUID.randomUUID().toString());
        Assertions.assertThat(BalanceTracker.INSTANCE.getLastKnownBalance()).isEmpty();
    }

}

@@ -1523,24 +1523,51 @@
 .isEmpty();%0A
+        // store new value%0A
         fina
@@ -1590,16 +1590,16 @@
  = 200;%0A
-
         
@@ -1758,32 +1758,277 @@
 ue(newBalance);%0A
+        // overwrite value%0A        final int newerBalance = 100;%0A        BalanceTracker.INSTANCE.setLastKnownBalance(newerBalance);%0A        Assertions.assertThat(BalanceTracker.INSTANCE.getLastKnownBalance()).isPresent().hasValue(newerBalance);%0A
         Assertio
@@ -2094,24 +2094,47 @@
 sPresent();%0A
+        // reset value%0A
         Asse

Extend coverage in balance tracker to include value overwriting