<commit_before>package com.canoo.dolphin.server;

/**
 * Created by hendrikebbers on 30.03.15.
 */
public class TestPropertyChange {
}<commit_msg>Test für PropertyChanged<commit_after>package com.canoo.dolphin.server;

import com.canoo.dolphin.mapping.ValueChangeEvent;
import com.canoo.dolphin.mapping.ValueChangeListener;
import com.canoo.dolphin.server.util.AbstractDolphinBasedTest;
import com.canoo.dolphin.server.util.SimpleTestModel;
import org.junit.Test;
import org.opendolphin.core.Attribute;
import org.opendolphin.core.server.ServerDolphin;
import org.opendolphin.core.server.ServerPresentationModel;

import static org.junit.Assert.assertEquals;

/**
 * Created by hendrikebbers on 30.03.15.
 */
public class TestPropertyChange extends AbstractDolphinBasedTest {

    private String newValue;

    private String oldValue;

    private boolean listenerCalled;

    @Test
    public void testWithAnnotatedSimpleModel() {
        ServerDolphin dolphin = createServerDolphin();
        BeanManager manager = new BeanManager(dolphin);

        final SimpleTestModel model = manager.create(SimpleTestModel.class);

        ValueChangeListener<String> myListener = new ValueChangeListener<String>() {
            @Override
            public void valueChanged(ValueChangeEvent<? extends String> evt) {
                assertEquals(model.getTextProperty(), evt.getSource());
                newValue = evt.getNewValue();
                oldValue = evt.getOldValue();
                listenerCalled = true;
            }
        };

        model.getTextProperty().addValueListener(myListener);
        assertEquals(null, newValue);
        assertEquals(null, oldValue);
        assertEquals(false, listenerCalled);

        model.getTextProperty().set("Hallo Property");
        assertEquals("Hallo Property", newValue);
        assertEquals(null, oldValue);
        assertEquals(true, listenerCalled);

        listenerCalled = false;
        model.getTextProperty().set("Hallo Property2");
        assertEquals("Hallo Property2", newValue);
        assertEquals("Hallo Property", oldValue);
        assertEquals(true, listenerCalled);

        listenerCalled = false;
        model.getTextProperty().removeValueListener(myListener);
        model.getTextProperty().set("Hallo Property3");
        assertEquals("Hallo Property2", newValue);
        assertEquals("Hallo Property", oldValue);
        assertEquals(false, listenerCalled);
    }
}
{'fraction_non_alphanumeric': 0.09959183673469388, 'fraction_numerical': 0.006530612244897959, 'mean_word_length': 3.4482758620689653, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7393860', 'n_tokens_mistral': 667, 'n_tokens_neox': 631, 'n_words': 127}