From 6c0b5563fbc8b0fbf9ed0aa722302a8f1e74cdf4 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 11 Sep 2016 10:12:36 +0200 Subject: SONAR-7851 add QProfileChangeDao --- .../org/sonar/core/util/SequenceUuidFactory.java | 36 +++++++++++++++++++++ .../sonar/core/util/SequenceUuidFactoryTest.java | 37 ++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 sonar-core/src/main/java/org/sonar/core/util/SequenceUuidFactory.java create mode 100644 sonar-core/src/test/java/org/sonar/core/util/SequenceUuidFactoryTest.java (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/core/util/SequenceUuidFactory.java b/sonar-core/src/main/java/org/sonar/core/util/SequenceUuidFactory.java new file mode 100644 index 00000000000..c35f78c71dc --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/util/SequenceUuidFactory.java @@ -0,0 +1,36 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.util; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Only for tests. This implementation of {@link UuidFactory} generates + * ids as a sequence of integers ("1", "2", ...). It starts with "1". + */ +public class SequenceUuidFactory implements UuidFactory { + + private final AtomicInteger id = new AtomicInteger(1); + + @Override + public String create() { + return String.valueOf(id.getAndIncrement()); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/util/SequenceUuidFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/util/SequenceUuidFactoryTest.java new file mode 100644 index 00000000000..2ca09ce5907 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/util/SequenceUuidFactoryTest.java @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.util; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class SequenceUuidFactoryTest { + + private SequenceUuidFactory underTest = new SequenceUuidFactory(); + + @Test + public void generate_sequence_of_integer_ids() { + for (int i = 1; i < 10; i++) { + assertThat(underTest.create()).isEqualTo(String.valueOf(i)); + } + } +} -- cgit v1.2.3