Repository: bevyengine/bevy
File: crates/bevy_winit/src/state.rs (Rust)

Code before:
        let (mut app, window_entity) = setup_react_to_scale_factor_change_test_app(1.0, 1.0);
        app.update();

        let window = app.world().get::<Window>(window_entity);
        assert_eq!(window.unwrap().resolution.scale_factor(), 1.0);

        let window_backend_scale_factor_changed = app
            .world()
            .resource::<Events<WindowBackendScaleFactorChanged>>();
        assert_eq!(window_backend_scale_factor_changed.len(), 1);

        let mut window_backend_scale_factor_changed_reader =
            window_backend_scale_factor_changed.get_cursor();
        let mut window_backend_scale_factor_changed_iter =
            window_backend_scale_factor_changed_reader.read(window_backend_scale_factor_changed);
        assert_eq!(
            window_backend_scale_factor_changed_iter.next(),
            Some(&WindowBackendScaleFactorChanged {
                window: window_entity,
                scale_factor: 1.0,
            })
        );

        let window_scale_factor_changed =
            app.world().resource::<Events<WindowScaleFactorChanged>>();
        assert_eq!(window_scale_factor_changed.len(), 0);
    }

    fn setup_react_to_scale_factor_change_test_app(
        initial_scale_factor: f32,
        changed_scale_factor: f64,
    ) -> (App, Entity) {
        let mut app = App::new();
        app.add_event::<WindowBackendScaleFactorChanged>();
        app.add_event::<WindowScaleFactorChanged>();
        app.add_systems(
            Update,
            move |mut window: Single<(Entity, &mut Window)>,
             mut window_backend_scale_factor_changed: EventWriter<
                WindowBackendScaleFactorChanged,
            >,
             mut window_scale_factor_changed: EventWriter<WindowScaleFactorChanged>| {
                react_to_scale_factor_change(
                    window.0,
                    &mut window.1,
                    changed_scale_factor,
                    &mut window_backend_scale_factor_changed,
                    &mut window_scale_factor_changed,
                );
            },
        );

Review comment (suggestion):
```suggestion
        assert!(window_scale_factor_changed.is_empty());
```

Code after:
        app.update();

        let window = app.world().get::<Window>(window_entity);
        assert_eq!(window.unwrap().resolution.scale_factor(), 1.0);

        let window_backend_scale_factor_changed_events = app
            .world()
            .resource::<Events<WindowBackendScaleFactorChanged>>();
        assert_eq!(window_backend_scale_factor_changed_events.len(), 1);

        let mut window_backend_scale_factor_changed_events_iter =
            window_backend_scale_factor_changed_events.iter_current_update_events();
        assert_eq!(
            window_backend_scale_factor_changed_events_iter.next(),
            Some(&WindowBackendScaleFactorChanged {
                window: window_entity,
                scale_factor: 1.0,
            })
        );
        assert_eq!(window_backend_scale_factor_changed_events_iter.next(), None);

        let window_scale_factor_changed_events =
            app.world().resource::<Events<WindowScaleFactorChanged>>();
        assert!(window_scale_factor_changed_events.is_empty());
    }

    fn setup_react_to_scale_factor_change_test_app(
        initial_scale_factor: f32,
        changed_scale_factor: f64,
    ) -> (App, Entity) {
        let mut app = App::new();
        app.add_event::<WindowBackendScaleFactorChanged>();
        app.add_event::<WindowScaleFactorChanged>();
        app.add_systems(
            Update,
            move |mut window: Single<(Entity, &mut Window)>,
             mut window_backend_scale_factor_changed: EventWriter<
                WindowBackendScaleFactorChanged,
            >,
             mut window_scale_factor_changed: EventWriter<WindowScaleFactorChanged>| {
                react_to_scale_factor_change(
                    window.0,
                    &mut window.1,
                    changed_scale_factor,
                    &mut window_backend_scale_factor_changed,
                    &mut window_scale_factor_changed,
                );
            },
        );

        let mut window = Window::default();