package com.mesosphere.sdk.config.validate;

import com.mesosphere.sdk.offer.InvalidRequirementException;
import com.mesosphere.sdk.specification.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.*;

import static org.mockito.Mockito.when;

/**
 * Tests for {@link ServiceNameCannotContainDoubleUnderscores}.
 */
public class ServiceNameCannotContainDoubleUnderscoresTest {
    private static final ConfigValidator<ServiceSpec> VALIDATOR = new ServiceNameCannotContainDoubleUnderscores();

    // Avoid spec validator hell by just using a mock object:
    @Mock private ServiceSpec mockServiceSpec;

    @Before
    public void beforeEach() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testDoubleUnderscores() throws InvalidRequirementException {
        when(mockServiceSpec.getName()).thenReturn("svc__1");
        Assert.assertEquals(1, VALIDATOR.validate(Optional.empty(), mockServiceSpec).size());
    }

    @Test
    public void testSingleUnderscores() throws InvalidRequirementException {
        when(mockServiceSpec.getName()).thenReturn("svc_1");
        Assert.assertEquals(0, VALIDATOR.validate(Optional.empty(), mockServiceSpec).size());
    }

    @Test
    public void testNoUnderscores() throws InvalidRequirementException {
        when(mockServiceSpec.getName()).thenReturn("svc1");
        Assert.assertEquals(0, VALIDATOR.validate(Optional.empty(), mockServiceSpec).size());
    }
}

@@ -139,17 +139,27 @@
 ication.
-*
+ServiceSpec
 ;%0Aimport
@@ -307,17 +307,24 @@
 va.util.
-*
+Optional
 ;%0A%0Aimpor
@@ -679,16 +679,20 @@
    @Mock
+%0A   
  private
@@ -808,32 +808,283 @@
 s(this);%0A    %7D%0A%0A
+    @Test%0A    public void testTripleUnderscores() throws InvalidRequirementException %7B%0A        when(mockServiceSpec.getName()).thenReturn(%22svc___1%22);%0A        Assert.assertEquals(1, VALIDATOR.validate(Optional.empty(), mockServiceSpec).size());%0A    %7D%0A%0A
     @Test%0A    pu

Add tripple underscore check to service name