|
| 1 | +/* |
| 2 | + * goPaint is designed to simplify painting inside of Minecraft. |
| 3 | + * Copyright (C) Arcaniax-Development |
| 4 | + * Copyright (C) Arcaniax team and contributors |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | +package net.onelitefeather.bettergopaint.brush; |
| 20 | + |
| 21 | +import net.onelitefeather.bettergopaint.menu.BrushMenuFactory; |
| 22 | +import net.onelitefeather.bettergopaint.objects.brush.Brush; |
| 23 | +import net.onelitefeather.bettergopaint.settings.Settings; |
| 24 | +import net.onelitefeather.bettergopaint.settings.SettingsHolder; |
| 25 | +import org.junit.jupiter.api.DisplayName; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +import java.security.SecureRandom; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | +import static org.mockito.Mockito.mock; |
| 32 | + |
| 33 | +class ExportedPlayerBrushRandomTest { |
| 34 | + |
| 35 | + private final Settings settings = Settings.defaults(); |
| 36 | + private final PlayerBrushManager manager = new PlayerBrushManager(SettingsHolder.of(settings), mock(BrushMenuFactory.class)); |
| 37 | + private final Brush disc = manager.getBrushByName("Disc Brush").orElseThrow(); |
| 38 | + |
| 39 | + @Test |
| 40 | + @DisplayName("the jitter source of an exported brush is not a cryptographic generator") |
| 41 | + void jitterSourceIsNotSecureRandom() { |
| 42 | + ExportedPlayerBrush brush = ExportedPlayerBrush.builder(disc, settings).build(); |
| 43 | + |
| 44 | + assertThat(brush.random()) |
| 45 | + .as("brush jitter needs no cryptographic strength, a SecureRandom is a synchronized hot spot") |
| 46 | + .isNotInstanceOf(SecureRandom.class); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + @DisplayName("exported brushes built from the same values are equal") |
| 51 | + void exportedBrushesBuiltFromSameValuesAreEqual() { |
| 52 | + ExportedPlayerBrush first = ExportedPlayerBrush.builder(disc, settings).size(3).chance(50).build(); |
| 53 | + ExportedPlayerBrush second = ExportedPlayerBrush.builder(disc, settings).size(3).chance(50).build(); |
| 54 | + |
| 55 | + assertThat(first) |
| 56 | + .as("record equality must depend only on the brush values, not on a randomness source") |
| 57 | + .isEqualTo(second); |
| 58 | + } |
| 59 | +} |
0 commit comments