/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
package org.elasticsearch.xpack.core.rollup.job;

import org.elasticsearch.cluster.Diff;
import org.elasticsearch.cluster.Diffable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class RollupJobTests extends AbstractDiffableSerializationTestCase {
    @Override
    protected Writeable.Reader<Diff> diffReader() {
        return RollupJob::readJobDiffFrom;
    }

    @Override
    protected ToXContent doParseInstance(XContentParser parser) throws IOException {
        return RollupJob.fromXContent(parser);
    }

    @Override
    protected Writeable.Reader instanceReader() {
        return RollupJob::new;
    }

    @Override
    protected Writeable createTestInstance() {
        if (randomBoolean()) {
            return new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), null);
        }

        Map<String, String> headers = Collections.emptyMap();
        if (randomBoolean()) {
            headers = new HashMap<>(1);
            headers.put("foo", "bar");
        }
        return new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), headers);
    }

    @Override
    protected Diffable makeTestChanges(Diffable testInstance) {
        RollupJob other = (RollupJob) testInstance;
        if (randomBoolean()) {
            if (other.getHeaders().isEmpty()) {
                Map<String, String> headers = new HashMap<>(1);
                headers.put("foo", "bar");
                return new RollupJob(other.getConfig(), headers);
            } else {
                return new RollupJob(other.getConfig(), null);
            }
        } else {
            return new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), other.getHeaders());
        }
    }
}

@@ -354,129 +354,33 @@
 ch.c
-luster.Diffable;%0Aimport org.elasticsearch.common.io.stream.Writeable;%0Aimport org.elasticsearch.common.xcontent.ToXContent
+ommon.io.stream.Writeable
 ;%0Aim
@@ -746,16 +746,27 @@
 TestCase
+%3CRollupJob%3E
  %7B%0A    @
@@ -809,16 +809,27 @@
 der%3CDiff
+%3CRollupJob%3E
 %3E diffRe
@@ -919,18 +919,17 @@
 ted 
-ToXContent
+RollupJob
  doP
@@ -1083,16 +1083,27 @@
 e.Reader
+%3CRollupJob%3E
  instanc
@@ -1180,25 +1180,25 @@
 otected 
-Writeable
+RollupJob
  createT
@@ -1653,24 +1653,25 @@
 otected 
-Diffable
+RollupJob
  makeTes
@@ -1683,84 +1683,26 @@
 ges(
-Diffable testInstance) %7B%0A        RollupJob other = (RollupJob) testInstance;
+RollupJob other) %7B
 %0A   

Fix bare warnings on RollupJobTests (#50633)